DBA Data[Home] [Help]

APPS.PA_FP_CI_MERGE SQL Statements

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

Line: 64

  API inserts records in the merged control items table
  and links two control items that have already merged.
  */

PROCEDURE FP_CI_LINK_CONTROL_ITEMS
(
  p_project_id           IN  NUMBER,
  p_s_fp_version_id      IN  pa_budget_versions.budget_version_id%TYPE,
  p_t_fp_version_id      IN  pa_budget_versions.budget_version_id%TYPE,
  p_inclusion_method     IN  VARCHAR2,
  p_included_by               IN  NUMBER,
  --Added for bug 3550073
  p_version_type        IN  pa_budget_versions.version_type%TYPE,
  p_ci_id               IN  pa_control_items.ci_id%TYPE,
  p_cost_ppl_qty        IN  pa_fp_merged_ctrl_items.impl_quantity%TYPE,
  p_rev_ppl_qty         IN  pa_fp_merged_ctrl_items.impl_quantity%TYPE,
  p_cost_equip_qty      IN  pa_fp_merged_ctrl_items.impl_equipment_quantity%TYPE,
  p_rev_equip_qty       IN  pa_fp_merged_ctrl_items.impl_equipment_quantity%TYPE,
  p_impl_pfc_raw_cost   IN  pa_fp_merged_ctrl_items.impl_proj_func_raw_cost%TYPE,
  p_impl_pfc_revenue    IN  pa_fp_merged_ctrl_items.impl_proj_func_revenue%TYPE,
  p_impl_pfc_burd_cost  IN  pa_fp_merged_ctrl_items.impl_proj_func_burdened_cost%TYPE,
  p_impl_pc_raw_cost    IN  pa_fp_merged_ctrl_items.impl_proj_raw_cost%TYPE,
  p_impl_pc_revenue     IN  pa_fp_merged_ctrl_items.impl_proj_revenue%TYPE,
  p_impl_pc_burd_cost   IN  pa_fp_merged_ctrl_items.impl_proj_burdened_cost%TYPE,
  p_impl_agr_revenue    IN  pa_fp_merged_ctrl_items.impl_agr_revenue%TYPE,
  x_return_status        OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
  x_msg_count            OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
  x_msg_data             OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
 )
 IS
-- Local Variable Declaration

      l_last_updated_by       NUMBER := FND_GLOBAL.USER_ID;
Line: 99

      l_last_update_date      DATE   := l_creation_date;
Line: 100

      l_last_update_login   NUMBER := FND_GLOBAL.LOGIN_ID;
Line: 208

            SELECT
                  bv.ci_id
            INTO
                  l_s_ci_id
            FROM  pa_budget_versions bv
            WHERE bv.budget_version_id = p_s_fp_version_id
            AND   bv.project_id = p_project_id;
Line: 234

          SELECT hp.party_id
          INTO
               l_party_id
          FROM      fnd_user fu,
               hz_parties hp
          WHERE
             user_id = l_included_by
             and employee_id IS NOT NULL
             and hp.orig_system_reference = 'PER:' || fu.employee_id;
Line: 245

        SELECT hp.party_id
        INTO   l_party_id
        FROM   fnd_user fu,
               hz_parties hp
        WHERE
              user_id = l_included_by
        AND   employee_id IS NULL
        -- Bug 4931044: R12 ATG Mandate: Moving customer_id to
        --   person_party_id in fnd_user
        AND   hp.party_id =  fu.person_party_id;
Line: 260

        INSERT INTO pa_fp_merged_ctrl_items
        (
             PROJECT_ID
            ,PLAN_VERSION_ID
            ,CI_ID
            ,CI_PLAN_VERSION_ID
            ,RECORD_VERSION_NUMBER
            ,last_update_date
            ,last_updated_by
            ,creation_date
            ,created_by
            ,last_update_login
            ,inclusion_method_code
            ,included_by_person_id
            --Included for bug 3550073
            ,version_type
            ,impl_proj_func_raw_cost
            ,impl_proj_func_burdened_cost
            ,impl_proj_func_revenue
            ,impl_proj_raw_cost
            ,impl_proj_burdened_cost
            ,impl_proj_revenue
            ,impl_quantity
            ,impl_equipment_quantity
            ,impl_agr_revenue
        )
        VALUES
        (
             p_project_id
            ,p_t_fp_version_id
            ,l_s_ci_id
            ,p_s_fp_version_id
            ,1
            ,l_last_update_date
            ,l_last_updated_by
            ,l_creation_date
            ,l_created_by
            ,l_last_update_login
            ,p_inclusion_method
            ,l_party_id
            --Included for bug 3550073
            ,'COST'
            ,p_impl_pfc_raw_cost
            ,p_impl_pfc_burd_cost
            ,NULL
            ,p_impl_pc_raw_cost
            ,p_impl_pc_burd_cost
            ,NULL
            ,p_cost_ppl_qty
            ,p_cost_equip_qty
            ,NULL
        );
Line: 315

        INSERT INTO pa_fp_merged_ctrl_items
        (
             PROJECT_ID
            ,PLAN_VERSION_ID
            ,CI_ID
            ,CI_PLAN_VERSION_ID
            ,RECORD_VERSION_NUMBER
            ,last_update_date
            ,last_updated_by
            ,creation_date
            ,created_by
            ,last_update_login
            ,inclusion_method_code
            ,included_by_person_id
            --Included for bug 3550073
            ,version_type
            ,impl_proj_func_raw_cost
            ,impl_proj_func_burdened_cost
            ,impl_proj_func_revenue
            ,impl_proj_raw_cost
            ,impl_proj_burdened_cost
            ,impl_proj_revenue
            ,impl_quantity
            ,impl_equipment_quantity
            ,impl_agr_revenue
        )
        VALUES
        (
             p_project_id
            ,p_t_fp_version_id
            ,l_s_ci_id
            ,p_s_fp_version_id
            ,1
            ,l_last_update_date
            ,l_last_updated_by
            ,l_creation_date
            ,l_created_by
            ,l_last_update_login
            ,p_inclusion_method
            ,l_party_id
            --Included for bug 3550073
            ,'REVENUE'
            ,NULL
            ,NULL
            ,p_impl_pfc_revenue
            ,NULL
            ,NULL
            ,p_impl_pc_revenue
            ,p_rev_ppl_qty
            ,p_rev_equip_qty
            ,p_impl_agr_revenue
        );
Line: 393

  This API is called to update the estimated amounts for control
  items budget versions. The main updation in this API is to update
  the estimated amounts for the target budget version of control item
  ***************************************************************/

  PROCEDURE FP_CI_UPDATE_EST_AMOUNTS
  (
    p_project_id         IN pa_budget_versions.project_id%TYPE,
    p_source_version_id       IN pa_budget_versions.budget_version_id%TYPE,
    p_target_version_id       IN pa_budget_versions.budget_version_id%TYPE,
    p_merge_unmerge_mode IN VARCHAR2 ,
    p_commit_flag        IN VARCHAR2 ,
    p_init_msg_list      IN VARCHAR2 ,
    p_update_agreement        IN VARCHAR2,
    x_return_status      OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
    x_msg_count          OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
    x_msg_data           OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
   )
   IS
  -- Local Variable Declaration

        l_last_updated_by     NUMBER := FND_GLOBAL.USER_ID;
Line: 415

     l_last_update_date       DATE := SYSDATE;
Line: 416

        l_last_update_login     NUMBER := FND_GLOBAL.LOGIN_ID;
Line: 434

         pa_debug.init_err_stack('PAFPCIMB.FP_CI_UPDATE_EST_AMOUNTS');
Line: 486

          SELECT bv.version_type
          INTO l_target_ver_type
          FROM pa_budget_versions bv
          WHERE
          bv.project_id = p_project_id
          AND bv.budget_version_id = p_target_version_id;
Line: 504

          SELECT
               NVL(est_project_raw_cost,0),
               NVL(est_project_burdened_cost,0),
               NVL(est_project_revenue,0),
               NVL(est_quantity,0),
               NVL(est_projfunc_raw_cost,0),
               NVL(est_projfunc_burdened_cost,0),
               NVL(est_projfunc_revenue,0),
            NVL(est_equipment_quantity,0),
               agreement_id
          INTO
               l_est_project_raw_cost,
               l_est_project_burdened_cost,
               l_est_project_revenue,
               l_est_quantity,
               l_est_projfunc_raw_cost,
               l_est_projfunc_burdened_cost,
               l_est_projfunc_revenue,
            l_est_equipment_quantity,
               l_agreement_id
          FROM PA_BUDGET_VERSIONS bv
          WHERE
          bv.project_id = p_project_id
          AND bv.budget_version_id = p_source_version_id;
Line: 541

          UPDATE PA_BUDGET_VERSIONS bv
          SET
          est_project_raw_cost = NVL(est_project_raw_cost,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_project_raw_cost,
                                             'UNMERGE', (-1 * l_est_project_raw_cost)),
          est_project_burdened_cost = NVL(est_project_burdened_cost,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_project_burdened_cost,
                                             'UNMERGE', (-1 * l_est_project_burdened_cost)),
          est_project_revenue = NVL(est_project_revenue,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_project_revenue,
                                             'UNMERGE', (-1 * l_est_project_revenue)),
          est_quantity = NVL(est_quantity,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_quantity,
                                             'UNMERGE', (-1 * l_est_quantity)),
        est_equipment_quantity=NVL(est_equipment_quantity,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_equipment_quantity,
                                             'UNMERGE', (-1 * l_est_equipment_quantity)),
          est_projfunc_raw_cost = NVL(est_projfunc_raw_cost,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_projfunc_raw_cost,
                                             'UNMERGE', (-1 * l_est_projfunc_raw_cost)),
          est_projfunc_burdened_cost = NVL(est_projfunc_burdened_cost,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_projfunc_burdened_cost,
                                             'UNMERGE', (-1 * l_est_projfunc_burdened_cost)),
          est_projfunc_revenue = NVL(est_projfunc_revenue,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_projfunc_revenue,
                                             'UNMERGE', (-1 * l_est_projfunc_revenue))
          WHERE
               bv.project_id = p_project_id
          AND bv.budget_version_id = p_target_version_id;
Line: 583

          UPDATE PA_BUDGET_VERSIONS bv
          SET
          est_project_raw_cost = NVL(est_project_raw_cost,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_project_raw_cost,
                                             'UNMERGE', (-1 * l_est_project_raw_cost)),
          est_project_burdened_cost = NVL(est_project_burdened_cost,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_project_burdened_cost,
                                             'UNMERGE', (-1 * l_est_project_burdened_cost)),
          est_quantity = NVL(est_quantity,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_quantity,
                                             'UNMERGE', (-1 * l_est_quantity)),
          est_projfunc_raw_cost = NVL(est_projfunc_raw_cost,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_projfunc_raw_cost,
                                             'UNMERGE', (-1 * l_est_projfunc_raw_cost)),
          est_projfunc_burdened_cost = NVL(est_projfunc_burdened_cost,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_projfunc_burdened_cost,
                                             'UNMERGE', (-1 * l_est_projfunc_burdened_cost))
          WHERE
               bv.project_id = p_project_id
          AND bv.budget_version_id = p_target_version_id;
Line: 613

          UPDATE PA_BUDGET_VERSIONS bv
          SET
          est_project_revenue = NVL(est_project_revenue,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_project_revenue,
                                             'UNMERGE', (-1 * l_est_project_revenue)),
          est_quantity = NVL(est_quantity,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_quantity,
                                             'UNMERGE', (-1 * l_est_quantity)),
          est_projfunc_revenue = NVL(est_projfunc_revenue,0) + DECODE
                                             (p_merge_unmerge_mode,
                                             'MERGE', l_est_projfunc_revenue,
                                             'UNMERGE', (-1 * l_est_projfunc_revenue))
          WHERE
               bv.project_id = p_project_id
          AND bv.budget_version_id = p_target_version_id;
Line: 636

     IF (p_update_agreement = 'Y') THEN
          UPDATE PA_BUDGET_VERSIONS bv
          SET
          agreement_id = l_agreement_id
          WHERE
               bv.project_id = p_project_id
          AND bv.budget_version_id = p_target_version_id;
Line: 655

                   'fp_ci_update_est_amounts'
                   ,p_procedure_name => PA_DEBUG.G_Err_Stack);
Line: 658

         PA_DEBUG.g_err_stage := 'Unexpected error in FP_CI_UPDATE_EST_AMOUNTS';
Line: 668

  END FP_CI_UPDATE_EST_AMOUNTS;
Line: 672

  This API is called to update the financial impact for control
  items. The main updation in this API is to update the status
  code of the impact and the person who caused that impact
  ***************************************************************/
  --Added p_impact_type_code for bug 3550073.
  --p_impact_type can be FINPLAN_COST, FINPLAN_REVENUE or
  --FINPLAN_BOTH in which case both FINPLAN_COST and FINPLAN_REVENUE records will be updated
  PROCEDURE FP_CI_UPDATE_IMPACT
  (
    p_ci_id                      IN  pa_ci_impacts.ci_id%TYPE,
    p_status_code            IN  pa_ci_impacts.status_code%TYPE,
    p_implementation_date     IN  pa_ci_impacts.implementation_date%TYPE,
    p_implemented_by          IN  pa_ci_impacts.implemented_by%TYPE,
    p_record_version_number   IN  pa_ci_impacts.record_version_number%TYPE,
    p_impacted_task_id        IN  pa_ci_impacts.impacted_task_id%TYPE,
    p_impact_type_code      IN  pa_ci_impacts.impact_type_code%TYPE,
    p_commit_flag            IN  VARCHAR2 ,
    p_init_msg_list          IN  VARCHAR2 ,
    x_return_status      OUT NOCOPY VARCHAR2, --File.Sql.39 bug 4440895
    x_msg_count          OUT NOCOPY NUMBER, --File.Sql.39 bug 4440895
    x_msg_data           OUT NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
   )
   IS
  -- Local Variable Declaration

        l_last_updated_by     NUMBER := FND_GLOBAL.USER_ID;
Line: 698

     l_last_update_date       DATE := SYSDATE;
Line: 699

        l_last_update_login     NUMBER := FND_GLOBAL.LOGIN_ID;
Line: 708

         pa_debug.init_err_stack('PAFPCIMB.FP_CI_UPDATE_IMPACT');
Line: 744

                               p_value1=>'FP_CI_UPDATE_IMPACT'
                                 );
Line: 761

          SELECT hp.party_id
          INTO
               l_party_id
          FROM      fnd_user fu,
               hz_parties hp
          WHERE
             user_id = l_implemented_by
             and employee_id IS NOT NULL
             and hp.orig_system_reference = 'PER:' || fu.employee_id;
Line: 772

               SELECT hp.party_id
               INTO
               l_party_id
               FROM fnd_user fu,
             hz_parties hp
          WHERE
             user_id = l_implemented_by
             and employee_id IS NULL
             -- Bug 4931044: R12 ATG Mandate: Moving customer_id to
             --    person_party_id in fnd_user
             and hp.party_id =  fu.person_party_id;
Line: 788

     UPDATE PA_CI_IMPACTS
     SET
         STATUS_CODE = NVL(p_status_code,status_code),
         IMPLEMENTATION_DATE = NVL(p_implementation_date,SYSDATE),
         IMPLEMENTED_BY = l_party_id,
         IMPACTED_TASK_ID = NVL(p_impacted_task_id,impacted_task_id),
         LAST_UPDATE_DATE = l_last_update_date,
         LAST_UPDATED_BY = l_last_updated_by,
         LAST_UPDATE_LOGIN = l_last_update_login,
         RECORD_VERSION_NUMBER = NVL(p_record_version_number, record_version_number +1)
         WHERE ci_id = p_ci_id
        AND   ((l_impact_type_code ='FINPLAN_BOTH' AND impact_type_code IN ('FINPLAN_COST', 'FINPLAN_REVENUE'))
          OR   (impact_type_code = l_impact_type_code));
Line: 813

                   'fp_ci_update_impact'
                   ,p_procedure_name => PA_DEBUG.G_Err_Stack);
Line: 816

         PA_DEBUG.g_err_stage := 'Unexpected error in FP_CI_UPDATE_IMPACT';
Line: 826

  END FP_CI_UPDATE_IMPACT;
Line: 916

       l_insert_flag          VARCHAR2(1) := 'N';
Line: 919

       l_update_agreement_flag     VARCHAR2(1) := 'N';
Line: 950

l_update_agreement_flag  := 'N';
Line: 964

SELECT COUNT(*) INTO l_t_count_versions
FROM pa_budget_versions bv
WHERE
bv.project_id = p_project_id
AND bv.ci_id = l_t_fp_ci_id
AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
     OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 973

SELECT count(*)
INTO l_target_plan_types_cnt
FROM pa_proj_fp_options po
WHERE
project_id = p_project_id
and fin_plan_option_level_code = 'PLAN_TYPE'
and (NVL(po.approved_rev_plan_type_flag,'N') = 'Y'
OR NVL(po.approved_cost_plan_type_flag,'N') = 'Y');
Line: 983

SELECT count(*)
INTO l_s_version_id_count
FROM pa_budget_versions bv
WHERE
bv.project_id = p_project_id
AND bv.ci_id = l_s_fp_ci_id
AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 995

     SELECT bv.budget_version_id
     BULK COLLECT INTO l_source_id_tbl
     FROM pa_budget_versions bv
     WHERE
     bv.project_id = p_project_id
     AND bv.ci_id = l_s_fp_ci_id
     AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
     OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 1011

     SELECT bv.version_type
     INTO l_source_ver_type
     FROM pa_budget_versions bv
     WHERE
     bv.project_id = p_project_id
     AND bv.budget_version_id = l_source_version_id;
Line: 1021

               SELECT bv.budget_version_id
               INTO l_target_version_id
               FROM pa_budget_versions bv
               WHERE
               bv.project_id = p_project_id
               AND bv.ci_id = l_t_fp_ci_id
               AND bv.version_type = l_source_ver_type
               AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
               OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 1073

               SELECT 'Y'
               INTO   l_impact_record_exists
               FROM   DUAL
               WHERE  EXISTS
                      (SELECT 1
                       FROM   pa_ci_impacts
                       WHERE  ci_id = l_t_fp_ci_id
                       AND    (l_s_version_type IN ('REVENUE','ALL') AND impact_type_code = 'FINPLAN_REVENUE'
                                OR l_s_version_type IN ('COST','ALL') AND impact_type_code = 'FINPLAN_COST'));
Line: 1166

           l_update_agreement_flag := 'Y';
Line: 1168

           UPDATE pa_budget_versions bv
           SET CI_ID = l_t_fp_ci_id
              ,VERSION_NUMBER = 1 -- bug 3677924
           WHERE
           p_project_id = bv.project_id
           AND bv.budget_version_id = l_target_version_id
           AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
           OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 1181

                    SELECT bv.budget_version_id
                    INTO l_target_version_id
                    FROM pa_budget_versions bv
                    WHERE
                    bv.project_id = p_project_id
                    AND bv.ci_id = l_t_fp_ci_id
                    AND bv.version_type = l_source_ver_type
                    AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
                    OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 1332

            l_update_agreement_flag     := 'N';
Line: 1368

               SELECT COUNT(*)
               INTO l_count_merged_versions
               FROM pa_fp_merged_ctrl_items
               WHERE
                    ci_plan_version_id = l_s_version_id
               AND  plan_version_id        = l_t_version_id
               AND  project_id        = p_project_id;
Line: 1436

      FP_CI_UPDATE_EST_AMOUNTS
       (
         p_project_id         => p_project_id,
         p_source_version_id       => l_source_version_id,
         p_target_version_id       => l_target_version_id,
         p_merge_unmerge_mode => p_merge_unmerge_mode ,
         p_commit_flag        => 'N' ,
         p_init_msg_list      => 'N',
         p_update_agreement        => l_update_agreement_flag,
         x_return_status      => x_return_status,
         x_msg_count          => x_msg_count,
         x_msg_data           => x_msg_data
       );
Line: 1456

     SELECT bv.budget_version_id
     BULK COLLECT INTO l_source_fp_version_id_tbl
     FROM pa_budget_versions bv
     WHERE
     bv.project_id = p_project_id
     AND bv.ci_id = l_s_fp_ci_id
     AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
     OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y')
     ORDER BY bv.version_type;
Line: 1505

                    SELECT 'Y'
                    INTO   l_impact_record_exists
                    FROM   DUAL
                    WHERE  EXISTS
                           (SELECT 1
                            FROM   pa_ci_impacts
                            WHERE  ci_id = l_t_fp_ci_id
                            AND    (l_s_version_type IN ('REVENUE') AND impact_type_code = 'FINPLAN_REVENUE'
                                     OR l_s_version_type IN ('COST') AND impact_type_code = 'FINPLAN_COST'));
Line: 1593

                    l_update_agreement_flag := 'Y';
Line: 1596

                    UPDATE pa_budget_versions bv
                    SET CI_ID = l_t_fp_ci_id
                       ,version_number = 1  -- Bug 3677924 Jul 06 2004 Raja
                    WHERE
                    p_project_id = bv.project_id
                    AND bv.budget_version_id = l_target_version_id
                    AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
                         OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 1606

                    FP_CI_UPDATE_EST_AMOUNTS
                     (
                       p_project_id         => p_project_id,
                       p_source_version_id       => l_source_version_id,
                       p_target_version_id       => l_target_version_id,
                       p_merge_unmerge_mode => p_merge_unmerge_mode ,
                       p_commit_flag        => 'N' ,
                       p_init_msg_list      => 'N',
                       p_update_agreement        => l_update_agreement_flag,
                       x_return_status      => x_return_status,
                       x_msg_count          => x_msg_count,
                       x_msg_data           => x_msg_data
                     );
Line: 1634

          SELECT bv.budget_version_id
          BULK COLLECT INTO l_target_fp_version_id_tbl
          FROM pa_budget_versions bv
          WHERE
          bv.project_id = p_project_id
          AND bv.ci_id = l_t_fp_ci_id
          AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
          OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y')
          ORDER BY bv.version_type;
Line: 1680

        l_update_agreement_flag    := 'N';
Line: 1690

                FP_CI_UPDATE_EST_AMOUNTS
        (
          p_project_id            => p_project_id,
          p_source_version_id => l_source_fp_version_id_tbl(i),
          p_target_version_id => l_target_fp_version_id_tbl(i),
          p_merge_unmerge_mode     => p_merge_unmerge_mode ,
          p_commit_flag           => 'N' ,
          p_init_msg_list          => 'N',
          p_update_agreement  => l_update_agreement_flag,
          x_return_status          => x_return_status,
          x_msg_count              => x_msg_count,
          x_msg_data               => x_msg_data
        );
Line: 1703

        /*FP_CI_UPDATE_EST_AMOUNTS
        (
          p_project_id            => p_project_id,
          p_source_version_id => l_s_version_id,
          p_target_version_id => l_t_version_id,
          p_merge_unmerge_mode     => p_merge_unmerge_mode ,
          p_commit_flag           => 'N' ,
          p_init_msg_list          => 'N',
          p_update_agreement  => l_update_agreement_flag,
          x_return_status          => x_return_status,
          x_msg_count              => x_msg_count,
          x_msg_data               => x_msg_data
        );*/
Line: 1729

               l_source_id_tbl.DELETE;
Line: 1857

                    SELECT COUNT(*)
                    INTO l_count_merged_versions
                    FROM pa_fp_merged_ctrl_items
                    WHERE
                         ci_plan_version_id = l_s_version_id
                    AND  plan_version_id        = l_t_version_id
                    AND  project_id        = p_project_id;
Line: 1921

                    l_update_agreement_flag := 'N';
Line: 1929

          SELECT bv.budget_version_id, bv.version_type
          INTO l_target_version_id, l_target_ver_type
          FROM pa_budget_versions bv
          WHERE
          bv.project_id = p_project_id
          AND bv.ci_id = l_t_fp_ci_id
          AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
          OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 1980

            l_update_agreement_flag     := 'N';
Line: 1985

            FP_CI_UPDATE_EST_AMOUNTS
            (
              p_project_id             => p_project_id,
              p_source_version_id  => l_source_fp_version_id_tbl(i),
              p_target_version_id  => l_target_version_id_tbl(1),
              p_merge_unmerge_mode => p_merge_unmerge_mode ,
              p_commit_flag            => 'N' ,
              p_init_msg_list      => 'N',
              p_update_agreement   => l_update_agreement_flag,
              x_return_status      => x_return_status,
              x_msg_count          => x_msg_count,
              x_msg_data           => x_msg_data
            );
Line: 1998

            /*FP_CI_UPDATE_EST_AMOUNTS
            (
              p_project_id             => p_project_id,
              p_source_version_id  => l_s_version_id,
              p_target_version_id  => l_t_version_id,
              p_merge_unmerge_mode => p_merge_unmerge_mode ,
              p_commit_flag            => 'N' ,
              p_init_msg_list      => 'N',
              p_update_agreement   => l_update_agreement_flag,
              x_return_status      => x_return_status,
              x_msg_count          => x_msg_count,
              x_msg_data           => x_msg_data
            );*/
Line: 2028

                SELECT bv.version_type
                INTO l_source_ver_type
                FROM pa_budget_versions bv
                WHERE bv.project_id = p_project_id
                AND   bv.budget_version_id = l_source_version_id;
Line: 2068

                         SELECT 'Y'
                         INTO   l_impact_record_exists
                         FROM   DUAL
                         WHERE  EXISTS
                                (SELECT 1
                                 FROM   pa_ci_impacts
                                 WHERE  ci_id = l_t_fp_ci_id
                                 AND    (l_s_version_type IN ('REVENUE') AND impact_type_code = 'FINPLAN_REVENUE'
                                          OR l_s_version_type IN ('COST') AND impact_type_code = 'FINPLAN_COST'));
Line: 2155

                         l_update_agreement_flag := 'Y';
Line: 2157

                         UPDATE pa_budget_versions bv
                         SET CI_ID = l_t_fp_ci_id
                         WHERE
                         p_project_id = bv.project_id
                         AND bv.budget_version_id = l_target_version_id
                         AND (NVL(bv.approved_rev_plan_type_flag,'N') = 'Y'
                              OR NVL(bv.approved_cost_plan_type_flag,'N') = 'Y');
Line: 2166

                         FP_CI_UPDATE_EST_AMOUNTS
                          (
                            p_project_id         => p_project_id,
                            p_source_version_id       => l_source_version_id,
                            p_target_version_id       => l_target_version_id,
                            p_merge_unmerge_mode => p_merge_unmerge_mode ,
                            p_commit_flag        => 'N' ,
                            p_init_msg_list      => 'N',
                            p_update_agreement        => l_update_agreement_flag,
                            x_return_status      => x_return_status,
                            x_msg_count          => x_msg_count,
                            x_msg_data           => x_msg_data
                          );
Line: 2194

                    l_source_id_tbl.DELETE;
Line: 2243

                    l_update_agreement_flag  := 'N';
Line: 2246

                    FP_CI_UPDATE_EST_AMOUNTS
                    (
                      p_project_id          => p_project_id,
                      p_source_version_id    => l_source_id_tbl(1),
                      p_target_version_id    => l_target_version_id_tbl(1),
                      p_merge_unmerge_mode   => p_merge_unmerge_mode ,
                      p_commit_flag              => 'N' ,
                      p_init_msg_list        => 'N',
                      p_update_agreement     => l_update_agreement_flag,
                      x_return_status        => x_return_status,
                      x_msg_count            => x_msg_count,
                      x_msg_data             => x_msg_data
                    );
Line: 2259

                    /*FP_CI_UPDATE_EST_AMOUNTS
                    (
                      p_project_id          => p_project_id,
                      p_source_version_id    => l_s_version_id,
                      p_target_version_id    => l_t_version_id,
                      p_merge_unmerge_mode   => p_merge_unmerge_mode ,
                      p_commit_flag              => 'N' ,
                      p_init_msg_list        => 'N',
                      p_update_agreement     => l_update_agreement_flag,
                      x_return_status        => x_return_status,
                      x_msg_count            => x_msg_count,
                      x_msg_data             => x_msg_data
                    );*/
Line: 2402

                        SELECT COUNT(*)
                        INTO l_count_merged_versions
                        FROM pa_fp_merged_ctrl_items
                        WHERE
                            ci_plan_version_id = l_s_version_id
                        AND   plan_version_id        = l_t_version_id
                        AND   project_id        = p_project_id;
Line: 2465

                        l_update_agreement_flag := 'N';
Line: 2467

                         FP_CI_UPDATE_EST_AMOUNTS
                          (
                            p_project_id          => p_project_id,
                            p_source_version_id        => l_s_version_id,
                            p_target_version_id        => l_t_version_id,
                            p_merge_unmerge_mode  => p_merge_unmerge_mode ,
                            p_commit_flag         => 'N' ,
                            p_init_msg_list       => 'N',
                            p_update_agreement         => l_update_agreement_flag,
                            x_return_status       => x_return_status,
                            x_msg_count           => x_msg_count,
                            x_msg_data            => x_msg_data
                          );
Line: 2528

                           - INSERT INTO pa_fp_merged_ctrl_items (

 ==================================================================*/

--Bug 4247703. Added the parameter p_calling_context. The valid values are NULL or GENERATION
PROCEDURE copy_merged_ctrl_items
   (  p_project_id            IN   pa_budget_versions.project_id%TYPE
     ,p_source_version_id     IN   pa_budget_versions.budget_version_id%TYPE
     ,p_target_version_id     IN   pa_budget_versions.budget_version_id%TYPE
     ,p_calling_context       IN   VARCHAR2
     ,x_return_status         OUT  NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
     ,x_msg_count             OUT  NOCOPY NUMBER --File.Sql.39 bug 4440895
     ,x_msg_data              OUT  NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
AS

l_msg_count                     NUMBER := 0;
Line: 2617

             (SELECT
                      p_project_id                     project_id
                     ,p_target_version_id              plan_version_id
                     ,pmc.ci_id                        ci_id
                     ,pmc.ci_plan_version_id           ci_plan_version_id
                     ,1                                record_version_number
                     ,sysdate                          creation_date
                     ,fnd_global.user_id               created_by
                     ,fnd_global.login_id              last_update_login
                     ,fnd_global.user_id               last_updated_by
                     ,sysdate                          last_update_date
                     ,'COPIED'                         inclusion_method_code
                     ,pmc.included_by_person_id        included_by_person_id
                     ,pmc.version_type                 version_type
                     ,pmc.impl_proj_func_raw_cost      impl_proj_func_raw_cost
                     ,pmc.impl_proj_func_burdened_cost impl_proj_func_burdened_cost
                     ,pmc.impl_proj_func_revenue       impl_proj_func_revenue
                     ,pmc.impl_proj_raw_cost           impl_proj_raw_cost
                     ,pmc.impl_proj_burdened_cost      impl_proj_burdened_cost
                     ,pmc.impl_proj_revenue            impl_proj_revenue
                     ,pmc.impl_quantity                impl_quantity
                     ,pmc.impl_equipment_quantity      impl_equipment_quantity
                     ,pmc.impl_agr_revenue             impl_agr_revenue
              FROM  pa_fp_merged_ctrl_items pmc,
                    pa_budget_versions sourcever,
                    pa_budget_versions targetver    -- Bug 3720445
              WHERE plan_version_id = p_source_version_id
              AND   sourcever.budget_version_id=p_source_version_id
              AND   targetver.budget_version_id=p_target_version_id   -- Bug 3720445
              AND   pmc.version_type = Decode (targetver.version_type, 'ALL', pmc.version_type,
                                                                        targetver.version_type)
              AND   (sourcever.fin_plan_type_id=targetver.fin_plan_type_id         OR
                     EXISTS (SELECT 1
                             FROM   pa_pt_co_impl_statuses ptco,
                                    pa_control_items pci
                             WHERE  ptco.fin_plan_type_id=targetver.fin_plan_type_id
                             AND    pci.ci_id=pmc.ci_id
                             AND    ptco.ci_type_id=pci.ci_type_id
                             AND    ptco.version_type=pmc.version_type
                             AND    ptco.status_code=pci.status_code))) source
          ON (target.project_id=source.project_id AND
              target.plan_version_id=source.plan_version_id AND
              target.ci_id=source.ci_id AND
              target.ci_plan_version_id=source.ci_plan_version_id AND
              target.version_type=source.version_type)
          WHEN MATCHED THEN
             UPDATE  SET target.last_update_date = sysdate
          WHEN NOT MATCHED THEN
             INSERT(
                    target.project_id
                   ,target.plan_version_id
                   ,target.ci_id
                   ,target.ci_plan_version_id
                   ,target.record_version_number
                   ,target.creation_date
                   ,target.created_by
                   ,target.last_update_login
                   ,target.last_updated_by
                   ,target.last_update_date
                   ,target.inclusion_method_code
                   ,target.included_by_person_id
                   ,target.version_type
                   ,target.impl_proj_func_raw_cost
                   ,target.impl_proj_func_burdened_cost
                   ,target.impl_proj_func_revenue
                   ,target.impl_proj_raw_cost
                   ,target.impl_proj_burdened_cost
                   ,target.impl_proj_revenue
                   ,target.impl_quantity
                   ,target.impl_equipment_quantity
                   ,target.impl_agr_revenue
                   )
            VALUES(
                    source.project_id
                   ,source.plan_version_id
                   ,source.ci_id
                   ,source.ci_plan_version_id
                   ,source.record_version_number
                   ,source.creation_date
                   ,source.created_by
                   ,source.last_update_login
                   ,source.last_updated_by
                   ,source.last_update_date
                   ,source.inclusion_method_code
                   ,source.included_by_person_id
                   ,source.version_type
                   ,source.impl_proj_func_raw_cost
                   ,source.impl_proj_func_burdened_cost
                   ,source.impl_proj_func_revenue
                   ,source.impl_proj_raw_cost
                   ,source.impl_proj_burdened_cost
                   ,source.impl_proj_revenue
                   ,source.impl_quantity
                   ,source.impl_equipment_quantity
                   ,source.impl_agr_revenue);
Line: 2722

          INSERT INTO pa_fp_merged_ctrl_items (
                   project_id
                  ,plan_version_id
                  ,ci_id
                  ,ci_plan_version_id
                  ,record_version_number
                  ,creation_date
                  ,created_by
                  ,last_update_login
                  ,last_updated_by
                  ,last_update_date
                  ,inclusion_method_code
                  ,included_by_person_id
                  ,version_type
                  ,impl_proj_func_raw_cost
                  ,impl_proj_func_burdened_cost
                  ,impl_proj_func_revenue
                  ,impl_proj_raw_cost
                  ,impl_proj_burdened_cost
                  ,impl_proj_revenue
                  ,impl_quantity
                  ,impl_equipment_quantity
                  ,impl_agr_revenue
                    )
          SELECT
                  p_project_id
                 ,p_target_version_id
                 ,pmc.ci_id
                 ,pmc.ci_plan_version_id
                 ,1
                 ,sysdate
                 ,fnd_global.user_id
                 ,fnd_global.login_id
                 ,fnd_global.user_id
                 ,sysdate
                 ,'COPIED'
                 ,pmc.included_by_person_id
                 ,pmc.version_type
                 ,pmc.impl_proj_func_raw_cost
                 ,pmc.impl_proj_func_burdened_cost
                 ,pmc.impl_proj_func_revenue
                 ,pmc.impl_proj_raw_cost
                 ,pmc.impl_proj_burdened_cost
                 ,pmc.impl_proj_revenue
                 ,pmc.impl_quantity
                 ,pmc.impl_equipment_quantity
                 ,pmc.impl_agr_revenue
          FROM  pa_fp_merged_ctrl_items pmc,
                pa_budget_versions sourcever,
                pa_budget_versions targetver    -- Bug 3720445
          WHERE plan_version_id = p_source_version_id
          AND   sourcever.budget_version_id=p_source_version_id
          AND   targetver.budget_version_id=p_target_version_id   -- Bug 3720445
          AND   pmc.project_id = p_project_id  -- Bug 4493425
          AND   pmc.version_type = Decode (targetver.version_type, 'ALL', pmc.version_type,
                                                                    targetver.version_type)
          AND   (sourcever.fin_plan_type_id=targetver.fin_plan_type_id         OR
                 EXISTS (SELECT 1
                         FROM   pa_pt_co_impl_statuses ptco,
                                pa_control_items pci
                         WHERE  ptco.fin_plan_type_id=targetver.fin_plan_type_id
                         AND    pci.ci_id=pmc.ci_id
                         AND    ptco.ci_type_id=pci.ci_type_id
                         AND    ptco.version_type=pmc.version_type
                         AND    ptco.status_code=pci.status_code)); -- Bug 3720445
Line: 2873

l_update_impact_allowed         varchar2(1);
Line: 2883

    SELECT pbvs.burdened_cost pfc_burd_cost,
           pbvs.revenue pfc_revenue,
           pbvs.raw_cost pfc_raw_cost,
           pbvs.total_project_raw_cost pc_raw_cost,
           pbvs.total_project_burdened_cost pc_burd_cost,
           pbvs.total_project_revenue pc_revenue,
           DECODE(pbvs.version_type,'REVENUE',NULL,pbvs.labor_quantity) cost_ppl_qty,
           DECODE(pbvs.version_type,'REVENUE',NULL,pbvs.equipment_quantity) cost_equip_qty,
           DECODE(pbvs.version_type,'REVENUE',pbvs.labor_quantity,NULL) rev_ppl_qty,
           DECODE(pbvs.version_type,'REVENUE',pbvs.equipment_quantity,NULL) rev_equip_qty
    FROM   pa_budget_versions pbvs
    WHERE  pbvs.budget_version_id=c_ci_version_id;
Line: 2953

      SELECT version_type
      BULK COLLECT INTO l_impl_version_type_tbl
      FROM   pa_fp_merged_ctrl_items
      WHERE  project_id=p_project_id
      AND    plan_version_id=p_t_fp_version_id
      AND    ci_id=p_ci_id
      AND    ci_plan_version_id IN ( NVL(p_ci_cost_version_id,-99),NVL(p_ci_rev_version_id,-99),NVL(p_ci_all_version_id,-99))
      AND    version_type IN ('COST','REVENUE');
Line: 3145

         call Pa_Fp_Control_Items_Utils.FP_CI_VALIDATE_UPDATE_IMPACT to determine whether we can
      update impact as implemented or not
      */

      Pa_Fp_Control_Items_Utils.FP_CI_VALIDATE_UPDATE_IMPACT
      (
        p_project_id               => p_project_id
       ,p_ci_id                    => p_ci_id
       ,p_source_version_id        => NULL
       ,p_target_version_id        => p_t_fp_version_id
       ,x_upd_cost_impact_allowed  => l_upd_cost_impact_allowed
       ,x_upd_rev_impact_allowed   => l_upd_rev_impact_allowed
       ,x_msg_data                 => x_msg_data
       ,x_msg_count                => x_msg_count
       ,x_return_status            => x_return_status
      );
Line: 3164

                pa_debug.g_err_stage:= 'Error calling Pa_Fp_Control_Items_Utils.FP_CI_VALIDATE_UPDATE_IMPACT';
Line: 3172

            pa_debug.g_err_stage:= 'l_update_impact_allowed' || l_update_impact_allowed;
Line: 3178

     call FP_CI_UPDATE_IMPACT if flag is Y.
     pass only ci id and the status code as we need to only them
     in this case.
      */
      IF l_upd_cost_impact_allowed = 'Y' THEN

          IF p_targ_version_type IN ('ALL','COST') THEN

              FP_CI_UPDATE_IMPACT
              (
                p_ci_id                => p_ci_id
                ,p_status_code          => 'CI_IMPACT_IMPLEMENTED'
                ,p_impact_type_code => 'FINPLAN_COST'
                ,p_commit_flag          => 'Y'
                ,x_return_status   => x_return_status
                ,x_msg_count       => x_msg_count
                ,x_msg_data             => x_msg_data
               );
Line: 3199

                    pa_debug.g_err_stage:= 'Error calling FP_CI_UPDATE_IMPACT';
Line: 3213

              FP_CI_UPDATE_IMPACT
              (
                p_ci_id                => p_ci_id
                ,p_status_code          => 'CI_IMPACT_IMPLEMENTED'
                ,p_impact_type_code => 'FINPLAN_REVENUE'
                ,p_commit_flag          => 'Y'
                ,x_return_status   => x_return_status
                ,x_msg_count       => x_msg_count
                ,x_msg_data             => x_msg_data
               );
Line: 3226

                    pa_debug.g_err_stage:= 'Error calling FP_CI_UPDATE_IMPACT';
Line: 3233

      END IF; -- update_impact_allowed = 'Y'
Line: 3318

   select decode(p_planning_level, 'P',0,'T',pt.top_task_id, pt.task_id)
   into l_src_targ_task_tbl(l_temp).value
   from pa_tasks pt
   where pt.task_id = p_task_id;
Line: 3345

        SELECT get_task_id(p_fin_plan_level_code,task_id),
               resource_list_member_id
        INTO   l_task_id,
               l_rlm_id
        FROM   pa_resource_assignments
        WHERE  resource_assignment_id=p_resource_assignment_id;
Line: 3391

        SELECT get_task_id(p_fin_plan_level_code,task_id),
               resource_list_member_id
        INTO   l_task_id,
               l_rlm_id
        FROM   pa_resource_assignments
        WHERE  resource_assignment_id=p_resource_assignment_id;
Line: 3439

                                      ,P_update_agreement_amt_flag  IN     VARCHAR2  DEFAULT  NULL -- Indicates whether to  update the agreement amt or not. Null is considered as N
                                      ,P_funding_category           IN     VARCHAR2  DEFAULT  NULL -- The funding category for the agreement
                                      ,p_raTxn_rollup_api_call_flag IN     VARCHAR2 -- Indicates whether the pa_resource_asgn_curr maintenance api should be called
                                      ,x_return_status              OUT    NOCOPY VARCHAR2 -- Indicates the exit status of the API --File.Sql.39 bug 4440895
                                      ,x_msg_data                   OUT    NOCOPY VARCHAR2 -- Indicates the error occurred --File.Sql.39 bug 4440895
                                      ,X_msg_count                  OUT    NOCOPY NUMBER)  -- Indicates the number of error messages --File.Sql.39 bug 4440895
IS

   -- Start of variables used for debugging purpose

     l_msg_count          NUMBER :=0;
Line: 3475

     l_id_before_bl_insertion    pa_budget_lines.budget_line_id%TYPE;
Line: 3476

     l_id_after_bl_insertion     pa_budget_lines.budget_line_id%TYPE;
Line: 3718

     l_delete_budget_lines_tbl         SYSTEM.pa_varchar2_1_tbl_type:=SYSTEM.pa_varchar2_1_tbl_type();
Line: 3843

          SELECT nvl(total_project_raw_cost,0)
                ,nvl(total_project_burdened_cost,0)
                ,nvl(total_project_revenue,0)
                ,nvl(raw_cost,0)
                ,nvl(burdened_cost,0)
                ,nvl(revenue,0)
                ,nvl(labor_quantity,0)
                ,nvl(equipment_quantity,0)
           FROM  pa_budget_versions
          WHERE  budget_version_id = p_budget_version_id;
Line: 3938

     SELECT pra.task_id, pra.resource_list_member_id, pra.resource_assignment_id,
            PA_PROJ_ELEMENTS_UTILS.GET_DISPLAY_SEQUENCE(pra.task_id) as dispSeq, rlm.alias
     FROM   pa_resource_assignments pra, pa_resource_list_members rlm
     WHERE  pra.budget_version_id = c_budget_version_id
     AND    rlm.resource_list_member_id = pra.resource_list_member_id
     AND    EXISTS (SELECT 1
                    FROM   pa_budget_lines pbl
                    WHERE  pbl.resource_assignment_id = pra.resource_assignment_id)
     ORDER BY dispSeq DESC , rlm.alias DESC;
Line: 3953

     SELECT pra.task_id, tmp4.resource_list_member_id, pra.resource_assignment_id,
            PA_PROJ_ELEMENTS_UTILS.GET_DISPLAY_SEQUENCE(pra.task_id) as dispSeq, rlm.alias
     FROM   pa_resource_assignments pra, pa_resource_list_members rlm,pa_res_list_map_tmp4 tmp4
     WHERE  pra.budget_version_id = c_budget_version_id
     AND    pra.resource_assignment_id=tmp4.txn_source_id
     AND    rlm.resource_list_member_id = tmp4.resource_list_member_id
     AND    EXISTS (SELECT 1
                    FROM   pa_budget_lines pbl
                    WHERE  pbl.resource_assignment_id = pra.resource_assignment_id)
     ORDER BY dispSeq DESC , rlm.alias DESC;
Line: 3968

     SELECT max(start_date)
     FROM   pa_budget_lines
     WHERE  resource_assignment_id = c_resource_assignment_id;
Line: 4034

          SELECT  etc_start_date
                 ,project_id
                 ,version_type
                 ,PA_PROJECT_STRUCTURE_UTILS.GET_FIN_STRUC_VER_ID(project_id )
                 ,nvl(labor_quantity,0)
                 ,nvl(equipment_quantity,0)
                 ,nvl(raw_cost,0)
                 ,nvl(burdened_cost,0)
                 ,nvl(revenue,0)
                 ,nvl(total_project_raw_cost,0)
                 ,nvl(total_project_burdened_cost,0)
                 ,nvl(total_project_revenue,0)
                 ,current_working_flag
          into    l_etc_start_date
                 ,l_project_id
                 ,l_target_version_type
                 ,l_project_structure_version_id
                 ,l_targ_lab_qty_before_merge
                 ,l_targ_eqp_qty_before_merge
                 ,l_targ_pfc_rawc_before_merge
                 ,l_targ_pfc_burdc_before_merge
                 ,l_targ_pfc_rev_before_merge
                 ,l_targ_pc_rawc_before_merge
                 ,l_targ_pc_burdc_before_merge
                 ,l_targ_pc_rev_before_merge
                 ,l_current_working_flag
          from   pa_budget_versions
          WHERE budget_version_id = p_budget_version_id;
Line: 4078

          SELECT project_currency_code
                ,projfunc_currency_code
                ,nvl(baseline_funding_flag,'N')
          INTO   l_project_currency_code
                ,l_projfunc_currency_code
                ,l_baseline_funding_flag
          FROM   pa_projects_all
          WHERE  project_id=l_project_id;
Line: 4099

          SELECT proj_fp_options_id,
                 plan_in_multi_curr_flag,
                 nvl(cost_time_phased_code,nvl(revenue_time_phased_code,all_time_phased_code)),
                 margin_derived_from_code,
                 approved_cost_plan_type_flag,
                 approved_rev_plan_type_flag,
                 nvl(cost_resource_list_id,nvl(revenue_resource_list_id,all_resource_list_id)),
                 rbs_version_id,
                 nvl(cost_fin_plan_level_code,nvl(revenue_fin_plan_level_code,all_fin_plan_level_code)),
                 decode(fin_plan_preference_code, 'COST_ONLY',    gen_cost_ret_manual_line_flag,
                                  'REVENUE_ONLY', gen_rev_ret_manual_line_flag,
                                 'COST_AND_REV_SAME', gen_all_ret_manual_line_flag)
          INTO   l_targ_proj_fp_options_id,
                 l_targ_multi_curr_flag,
                 l_targ_time_phased_code,
                 L_REPORT_COST_USING,
                 l_targ_app_cost_flag,
                 l_targ_app_rev_flag,
                 l_targ_resource_list_id,
                 l_rbs_version_id,
                 l_targ_plan_level_code,
                 l_retain_manual_lines_flag -- bug 3934574
          FROM   pa_proj_fp_options
          WHERE  fin_plan_version_id = p_budget_version_id
          AND    fin_plan_type_id    = p_fin_plan_type_id;
Line: 4394

         l_src_targ_task_tbl.delete;
Line: 4395

         l_res_assmt_map_rec_tbl.delete;
Line: 4411

                  SELECT impl_agr_revenue,
                         nvl(impl_proj_func_revenue,0), -- bug 4035856
                         nvl(impl_proj_revenue,0),      -- bug 4035856
                         nvl(impl_quantity,0)           -- bug 4035856
                  INTO   l_impl_amt,
                         l_impl_proj_func_revenue, -- bug 4035856
                         l_impl_proj_revenue,      -- bug 4035856
                         l_impl_quantity           -- bug 4035856
                  FROM   pa_fp_merged_ctrl_items
                  WHERE  project_id=l_project_id
                  AND    plan_version_id=p_budget_version_id
                  AND    ci_id=p_ci_id
                  AND    ci_plan_version_id=l_src_ver_id_tbl(j)
                  AND    version_type='REVENUE';
Line: 4440

                       SELECT nvl(sum(pbl.txn_revenue),0) total_amt,
                              nvl(sum(pbl.revenue),0) total_amt_in_pfc,
                              nvl(sum(pbl.project_revenue),0) total_amt_in_pc
                       INTO   L_total_amt,
                              l_total_amt_in_pfc,
                              l_total_amt_in_pc
                       FROM   Pa_budget_lines pbl
                       WHERE  pbl.budget_Version_id= l_src_ver_id_tbl(j);
Line: 4506

             SELECT NVL(sum(txn_revenue),0)
             INTO   l_partial_impl_rev_amt
             FROM   pa_budget_lines
             WHERE  budget_version_id=l_src_ver_id_tbl(j);
Line: 4526

              SELECT proj_fp_options_id,
                     plan_in_multi_curr_flag,
                     fin_plan_type_id,
                     nvl(cost_time_phased_code,nvl(revenue_time_phased_code,all_time_phased_code)),
                     report_labor_hrs_from_code,
                     nvl(cost_resource_list_id,nvl(revenue_resource_list_id,all_resource_list_id)),
                     nvl(cost_fin_plan_level_code,nvl(revenue_fin_plan_level_code,all_fin_plan_level_code))
              INTO   l_src_proj_fp_options_id,
                     l_src_multi_curr_flag,
                     l_src_fin_plan_type_id,
                     l_src_time_phased_code,
                     l_src_report_lbr_hrs_frm_code,
                     l_src_resource_list_id,
                     l_src_plan_level_code
              FROM   pa_proj_fp_options
              WHERE  fin_plan_version_id = l_src_ver_id_tbl(j);
Line: 4580

               SELECT ptxn_s.txn_currency_code
               BULK COLLECT INTO l_txn_curr_code_tbl
               FROM    pa_fp_txn_currencies ptxn_s
               WHERE   ptxn_s.proj_fp_options_id=l_src_proj_fp_options_id
               AND     NOT EXISTS (SELECT 'X'
                                   FROM   pa_fp_txn_currencies ptxn_t
                                   WHERE  ptxn_t.proj_fp_options_id=l_targ_proj_fp_options_id
                                   AND    ptxn_t.txn_currency_code=ptxn_s.txn_currency_code);
Line: 4593

                           pa_debug.g_err_stage:='INSERTING l_targ_proj_fp_options_id'||l_targ_proj_fp_options_id;
Line: 4596

                           pa_debug.g_err_stage:='INSERTING l_PROJECT_ID'||l_PROJECT_ID;
Line: 4599

                           pa_debug.g_err_stage:='INSERTING p_budget_version_id'||p_budget_version_id;
Line: 4602

                           pa_debug.g_err_stage:='INSERTING l_txn_curr_code_tbl'||l_txn_curr_code_tbl(i);
Line: 4610

                    INSERT INTO PA_FP_TXN_CURRENCIES (
                       fp_txn_currency_id
                       ,proj_fp_options_id
                       ,project_id
                       ,fin_plan_type_id
                       ,fin_plan_version_id
                       ,txn_currency_code
                       ,default_rev_curr_flag
                       ,default_cost_curr_flag
                       ,default_all_curr_flag
                       ,project_currency_flag
                       ,projfunc_currency_flag
                       ,last_update_date
                       ,last_updated_by
                       ,creation_date
                       ,created_by
                       ,last_update_login
                       ,project_cost_exchange_rate
                       ,project_rev_exchange_rate
                       ,projfunc_cost_exchange_Rate
                       ,projfunc_rev_exchange_Rate
                       )
                       VALUES
                       ( pa_fp_txn_currencies_s.NEXTVAL
                       , l_targ_proj_fp_options_id
                       , l_PROJECT_ID
                       , p_fin_plan_type_id
                       , p_budget_version_id
                       , l_txn_curr_code_tbl(jj)
                       , 'N'
                       , 'N'
                       , 'N'
                       , 'N'
                       , 'N'
                       , sysdate
                       , fnd_global.user_id
                       , sysdate
                       , fnd_global.user_id
                       , fnd_global.login_id
                       , NULL
                       , NULL
                       , NULL
                       , NULL);
Line: 4688

             SELECT rlmap.resource_list_member_id -- rlm id for the target
             ,DECODE(prat.resource_assignment_id,null, 'INSERT','UPDATE') --Indicates whether the records needs to be updated/inserted in the target
             ,get_task_id(l_targ_plan_level_code,rlmap.task_id),
              prat.resource_assignment_id,
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.txn_source_id),null),
             min(LEAST(nvl(prat.planning_start_date, rlmap.planning_start_date),rlmap.planning_start_date)),
             max(GREATEST(nvl(prat.planning_end_date, rlmap.planning_end_date),rlmap.planning_end_date)),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.txn_spread_curve_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.txn_etc_method_code),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.resource_type_code),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.fc_res_type_code),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.RESOURCE_CLASS_CODE),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.organization_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.job_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.person_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.expenditure_type),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.expenditure_category),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.revenue_category),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.event_type),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.vendor_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.project_role_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.person_type_code),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.non_labor_resource),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.bom_resource_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.inventory_item_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.item_category_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.mfc_cost_type_id),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.INCURRED_BY_RES_FLAG),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.RESOURCE_CLASS_FLAG),null),
             decode(COUNT(rlmap.txn_source_id),1,max(rlmap.NAMED_ROLE),null),
             NULL,
             NULL,
             NULL,
             NULL,
             NULL,
             --The below decodes will return the Rate Based Flag(rbf) and unit of measure(uom) for the target
             --resource assignment. These decodes will derive the rbf and uom based on following logic
             ------If multiple source planning transactions are being merged into a single target transaction
             ----------If the all the source planning transactions have same UOM AND RBF then
             --------------if the UOM and RBF are equal to those of target planning transaction then
             ------------------take UOM and RBF from the source
             --------------else
             ------------------take DOLLARS and N for UOM and RBF
             ----------else
             --------------take DOLLARS and N for UOM and RBF
             ------else if there is one to one mapping
             ----------If the UOM and RBF of the source and target plannig transactions are same then
             --------------take UOM and RBF from source
             ----------else
             --------------take DOLLARS and N for UOM and RBF
             ------else if there is no matching target transaction(In this case one should be inserted into target)
             ----------source's RBF and UOM will be compared with the RBF and UOM returned be get_resource_defaults.
             ----------This is done below
             decode(max(rlmap.rbf),
                    min(rlmap.rbf),decode(max(rlmap.uom),
                                          min(rlmap.uom),decode(prat.resource_assignment_id,
                                                                null, max(rlmap.rbf),
                                                                decode(max(rlmap.rbf),
                                                                       max(prat.rate_based_flag),decode(max(rlmap.uom),
                                                                                                        max(prat.unit_of_measure),max(rlmap.rbf),
                                                                                                        'N'),
                                                                      'N')),
                                         'N'),
                    'N'),
               /* bug 5073816: Changed the following */
                max(rlmap.rrbf),  --IPM Arch Enhancement
             decode(max(rlmap.rbf),
                    min(rlmap.rbf),decode(max(rlmap.uom),
                                          min(rlmap.uom),decode(prat.resource_assignment_id,
                                                                null, max(rlmap.uom),
                                                                decode(max(rlmap.rbf),
                                                                       max(prat.rate_based_flag),decode(max(rlmap.uom),
                                                                                                        max(prat.unit_of_measure),max(rlmap.uom),
                                                                                                        'DOLLARS'),
                                                                      'DOLLARS')),
                                         'DOLLARS'),
                    'DOLLARS'),
             --Bug 3752352. If the resource lists are differnt then initialise the rbs element id and
             --txn accum header tbls .
             NULL,
             NULL
             BULK COLLECT INTO
               L_targ_rlm_id_tbl,
               L_ra_dml_code_tbl,
               L_targ_task_id_tbl,
               L_targ_ra_id_tbl,
               l_src_ra_id_cnt_tbl,
               l_planning_start_date_tbl,
               l_planning_end_date_tbl,
               l_targ_spread_curve_id_tbl,
               l_targ_etc_method_code_tbl,
               l_targ_resource_type_code_tbl,
               l_targ_fc_res_type_code_tbl,
               l_targ_RESOURCE_CLASS_CODE_tbl,
               l_targ_organization_id_tbl,
               l_targ_job_id_tbl,
               l_targ_person_id_tbl,
               l_targ_expenditure_type_tbl,
               l_targ_expend_category_tbl,
               l_targ_rev_category_code_tbl,
               l_targ_event_type_tbl,
               l_targ_supplier_id_tbl,
               l_targ_project_role_id_tbl,
               l_targ_person_type_code_tbl,
               l_targ_non_labor_resource_tbl,
               l_targ_bom_resource_id_tbl,
               l_targ_inventory_item_id_tbl,
               l_targ_item_category_id_tbl,
               l_targ_mfc_cost_type_id_tbl,
               l_targ_INCURED_BY_RES_FLAG_tbl,
               l_targ_RESOURCE_CLASS_FLAG_tbl,
               l_targ_NAMED_ROLE_tbl ,
               l_targ_RATE_EXPEND_TYPE_tbl,
               l_targ_RATE_EXP_FC_CUR_COD_tbl,
               l_targ_RATE_EXPEND_ORG_ID_tbl,
               l_targ_INCR_BY_RES_CLS_COD_tbl,
               l_targ_INCUR_BY_ROLE_ID_tbl,
               l_targ_RATE_BASED_FLAG_tbl,
               l_targ_RES_RATE_BASED_FLAG_tbl, --IPM Arch Enhancement
               l_targ_unit_of_measure_tbl,
               l_targ_rbs_element_id_tbl,
               l_targ_txn_accum_header_id_tbl

             FROM    Pa_resource_assignments prat,
                     (SELECT
                       rlmap.txn_spread_curve_id,
                       rlmap.txn_etc_method_code,
                       rlmap.resource_type_code,
                       rlmap.fc_res_type_code,
                       rlmap.RESOURCE_CLASS_CODE,
                       rlmap.organization_id,
                       rlmap.job_id,
                       rlmap.person_id,
                       rlmap.expenditure_type,
                       rlmap.expenditure_category,
                       rlmap.revenue_category,
                       rlmap.event_type,
                       rlmap.vendor_id,
                       rlmap.project_role_id,
                       rlmap.person_type_code,
                       rlmap.non_labor_resource,
                       rlmap.bom_resource_id,
                       rlmap.inventory_item_id,
                       rlmap.item_category_id,
                       rlmap.mfc_cost_type_id,
                       rlmap.INCURRED_BY_RES_FLAG,
                       rlmap.TXN_RATE_BASED_FLAG,
                       rlmap.RESOURCE_CLASS_FLAG,
                       rlmap.NAMED_ROLE,
                       rlmap.txn_source_id,
                       rlmap.resource_list_member_id,
                       pra.planning_start_date,
                       pra.planning_end_date,
                       pra.task_id,
                       pra.rate_based_flag as rbf,
                       pra.resource_rate_based_flag as rrbf,    --IPM Arch Enhancement
                       pra.unit_of_measure as uom
                      FROM
                       pa_resource_assignments pra,
                       pa_res_list_map_tmp4 rlmap
                      WHERE
                       pra.resource_assignment_id=rlmap.txn_source_id)rlmap
             WHERE   prat.budget_version_id(+)=p_budget_version_id
             AND     prat.resource_list_member_id(+)=rlmap.resource_list_member_id
             AND     prat.task_id(+)=get_task_id(l_targ_plan_level_code,rlmap.task_id)
             AND     prat.project_assignment_id(+)=-1
/* Bug 7287101 - skkoppul - commented
             AND     (prat.resource_assignment_id is null  --> target ra doesnot exist
                      OR decode(p_calling_context,
                                 'BUDGET_GENERATION', decode(l_retain_manual_lines_flag, 'Y', prat.transaction_source_code, 'x'),
                                 'FORECAST_GENERATION', decode(l_retain_manual_lines_flag, 'Y', prat.transaction_source_code, 'x'),
                                   -99) is not null) -- bug 3934574 */
             GROUP BY get_task_id(l_targ_plan_level_code,rlmap.task_id) ,
                      rlmap.resource_list_member_id, prat.resource_assignment_id;
Line: 4865

                  pa_debug.g_err_stage:= 'About to select the RAs with same res list for INS/UPD';
Line: 4871

             SELECT pras.resource_list_member_id -- rlm id for the target
             ,DECODE(prat.resource_assignment_id,null, 'INSERT','UPDATE') --Indicates whether the records needs to be updated/inserted in the target
             , get_task_id(l_targ_plan_level_code,pras.task_id),
                prat.resource_assignment_id,
             decode(COUNT(pras.resource_assignment_id),1,max(pras.resource_assignment_id),null),
             min(LEAST(nvl(prat.planning_start_date, pras.planning_start_date),pras.planning_start_date)),
             max(GREATEST(nvl(prat.planning_end_date, pras.planning_end_date),pras.planning_end_date)),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.rbs_element_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.spread_curve_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.etc_method_code),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.fc_res_type_code),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.organization_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.job_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.person_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.expenditure_type),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.expenditure_category),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.revenue_category_code),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.event_type),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.supplier_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.project_role_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.res_type_code),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.person_type_code),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.non_labor_resource),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.bom_resource_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.inventory_item_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.item_category_id),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.INCURRED_BY_RES_FLAG),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.RESOURCE_CLASS_FLAG),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.NAMED_ROLE),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.TXN_ACCUM_HEADER_ID),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.RESOURCE_CLASS_CODE),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.ASSIGNMENT_DESCRIPTION),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.MFC_COST_TYPE_ID),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.RATE_JOB_ID),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.RATE_EXPENDITURE_TYPE),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.RATE_EXP_FUNC_CURR_CODE),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.RATE_EXPENDITURE_ORG_ID),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.INCUR_BY_RES_CLASS_CODE),null),
             decode(COUNT(pras.resource_assignment_id),1,max(pras.INCUR_BY_ROLE_ID),null),
             --The below decodes will return the Rate Based Flag(rbf) and unit of measure(uom) for the target
             --resource assignment. These decodes will derive the rbf and uom based on following logic
             ------If multiple source planning transactions are being merged into a single target transaction
             ----------If the all the source planning transactions have same UOM AND RBF then
             --------------if the UOM and RBF are equal to those of target planning transaction then
             ------------------take UOM and RBF from the source
             --------------else
             ------------------take DOLLARS and N for UOM and RBF
             ----------else
             --------------take DOLLARS and N for UOM and RBF
             ------else if there is one to one mapping
             ----------If the UOM and RBF of the source and target plannig transactions are same then
             --------------take UOM and RBF from source
             ----------else
             --------------take DOLLARS and N for UOM and RBF
             ------else if there is no matching target transaction(In this case one should be inserted into target)
             ----------source's RBF and UOM will be compared with the RBF and UOM returned be get_resource_defaults.
             ----------This is done below
             decode(max(pras.rate_based_flag),
                    min(pras.rate_based_flag),decode(max(pras.unit_of_measure),
                                                     min(pras.unit_of_measure),decode(prat.resource_assignment_id,
                                                                                      null,  max(pras.rate_based_flag),
                                                                                      decode(max(pras.rate_based_flag),
                                                                                             max(prat.rate_based_flag),decode(max(pras.unit_of_measure),
                                                                                                                              max(prat.unit_of_measure),max(pras.rate_based_flag),
                                                                                                                              'N'),
                                                                                             'N')),
                                                    'N'),
                    'N'),
            /* bug 5073816: Changed the following */
                max(pras.resource_rate_based_flag),    --IPM Arch Enhancement Bug 4865563
             decode(max(pras.rate_based_flag),
                    min(pras.rate_based_flag),decode(max(pras.unit_of_measure),
                                                     min(pras.unit_of_measure),decode(prat.resource_assignment_id,
                                                                                      null,  max(pras.unit_of_measure),
                                                                                      decode(max(pras.rate_based_flag),
                                                                                             max(prat.rate_based_flag),decode(max(pras.unit_of_measure),
                                                                                                                              max(prat.unit_of_measure),max(pras.unit_of_measure),
                                                                                                                              'DOLLARS'),
                                                                                             'DOLLARS')),
                                                     'DOLLARS'),
                   'DOLLARS')
             BULK COLLECT INTO
               L_targ_rlm_id_tbl,
               L_ra_dml_code_tbl,
               L_targ_task_id_tbl,
               L_targ_ra_id_tbl,
               l_src_ra_id_cnt_tbl,
               l_planning_start_date_tbl,
               l_planning_end_date_tbl,
               l_targ_rbs_element_id_tbl,
               l_targ_spread_curve_id_tbl,
               l_targ_etc_method_code_tbl,
               l_targ_fc_res_type_code_tbl,
               l_targ_organization_id_tbl,
               l_targ_job_id_tbl,
               l_targ_person_id_tbl,
               l_targ_expenditure_type_tbl,
               l_targ_expend_category_tbl,
               l_targ_rev_category_code_tbl,
               l_targ_event_type_tbl,
               l_targ_supplier_id_tbl,
               l_targ_project_role_id_tbl,
               l_targ_resource_type_code_tbl,
               l_targ_person_type_code_tbl,
               l_targ_non_labor_resource_tbl,
               l_targ_bom_resource_id_tbl,
               l_targ_inventory_item_id_tbl,
               l_targ_item_category_id_tbl,
               l_targ_INCURED_BY_RES_FLAG_tbl,
               l_targ_RESOURCE_CLASS_FLAG_tbl,
               l_targ_NAMED_ROLE_tbl,
               l_targ_txn_accum_header_id_tbl,
               l_targ_RESOURCE_CLASS_CODE_tbl,
               l_targ_assignment_description,
               l_targ_mfc_cost_type_id_tbl,
               l_targ_RATE_JOB_ID_tbl,
               l_targ_RATE_EXPEND_TYPE_tbl,
               l_targ_RATE_EXP_FC_CUR_COD_tbl,
               l_targ_RATE_EXPEND_ORG_ID_tbl,
               l_targ_INCR_BY_RES_CLS_COD_tbl,
               l_targ_INCUR_BY_ROLE_ID_tbl,
               l_targ_RATE_BASED_FLAG_tbl,
               l_targ_RES_RATE_BASED_FLAG_tbl,    --IPM Arch Enhancement Bug 4865563
               l_targ_unit_of_measure_tbl
             FROM    pa_resource_assignments pras,
                     Pa_resource_assignments prat
             WHERE   pras.budget_version_id=l_src_ver_id_tbl(j)
             AND     prat.budget_version_id(+)=p_budget_version_id
             AND     prat.resource_list_member_id(+)=pras.resource_list_member_id
             AND     prat.task_id(+)=get_task_id(l_targ_plan_level_code,pras.task_id)
             AND     prat.project_assignment_id(+)=-1
/* Bug 7287101 - skkoppul - commented
             AND     (prat.resource_assignment_id is null --> target ra doesnot exist
                      OR decode(p_calling_context,
                                 'BUDGET_GENERATION', decode(l_retain_manual_lines_flag, 'Y', prat.transaction_source_code, 'x'),
                                 'FORECAST_GENERATION', decode(l_retain_manual_lines_flag, 'Y', prat.transaction_source_code, 'x'),
                                   -99) is not null) -- bug 3934574 */
             GROUP BY get_task_id(l_targ_plan_level_code,pras.task_id) , pras.resource_list_member_id,
                       prat.resource_assignment_id;
Line: 5012

                  pa_debug.g_err_stage:= ' selected the RAs with same res list for INS/UPD '||l_targ_ra_id_tbl.count;
Line: 5038

                       SELECT pa_resource_assignments_s.nextval
                       INTO L_targ_ra_id_tbl(ind)
                       FROM dual;
Line: 5060

                       IF   L_ra_dml_code_tbl(kk) = 'INSERT'
                       AND l_src_ra_id_cnt_tbl(KK) IS NULL THEN

                            l_temp:= NULL;
Line: 5081

                          ELSIF L_ra_dml_code_tbl(kk) = 'INSERT'
                          AND l_src_ra_id_cnt_tbl(KK) IS NOT NULL THEN

                               l_temp := NULL; --Bug 5532905.
Line: 5220

                            IF   L_ra_dml_code_tbl(kk) = 'INSERT'
                            AND l_src_ra_id_cnt_tbl(KK) IS NULL THEN

                                l_temp:=1;
Line: 5286

                                      pa_debug.g_err_stage:= 'About to derive the rbs and UOM for the target txn that should be inserted';
Line: 5333

                            END IF; --IF   L_ra_dml_code_tbl(kk) = 'INSERT'
Line: 5417

                                IF   L_ra_dml_code_tbl(kk) = 'INSERT'
                                AND  l_src_ra_id_cnt_tbl(KK) IS NULL THEN

                                    l_temp:=1;
Line: 5446

                                END IF;--IF   L_ra_dml_code_tbl(kk) = 'INSERT'
Line: 5515

                                   IF   L_ra_dml_code_tbl(kk) = 'INSERT'
                                   AND  l_src_ra_id_cnt_tbl(KK) IS NOT NULL THEN
                                       l_temp:=1;
Line: 5560

                   IF  L_ra_dml_code_tbl(kk) = 'INSERT' THEN

                        l_temp:= NULL;
Line: 5650

                        IF l_ra_dml_code_tbl(kk)='INSERT'  THEN
                            l_temp:=1;
Line: 5715

                                  pa_debug.g_err_stage:= 'About to derive the rbs and UOM for the target txn that should be inserted';
Line: 5760

                        END IF;-- IF l_ra_dml_code_tbl(kk)='INSERT'  THEN
Line: 5846

                              IF l_ra_dml_code_tbl(kk)='INSERT'  THEN

                                  l_temp:=1;
Line: 5874

                              END IF;-- IF l_ra_dml_code_tbl(kk)='INSERT'  THEN
Line: 5890

                  pa_debug.g_err_stage:= 'About to bulk insert into PRA';
Line: 5929

            INSERT INTO PA_RESOURCE_ASSIGNMENTS (
                    RESOURCE_ASSIGNMENT_ID,BUDGET_VERSION_ID,PROJECT_ID,TASK_ID,RESOURCE_LIST_MEMBER_ID,LAST_UPDATE_DATE,LAST_UPDATED_BY,CREATION_DATE,CREATED_BY
                    ,LAST_UPDATE_LOGIN,UNIT_OF_MEASURE,TRACK_AS_LABOR_FLAG,STANDARD_BILL_RATE,AVERAGE_BILL_RATE,AVERAGE_COST_RATE
                    ,PROJECT_ASSIGNMENT_ID,PLAN_ERROR_CODE,TOTAL_PLAN_REVENUE,TOTAL_PLAN_RAW_COST,TOTAL_PLAN_BURDENED_COST,TOTAL_PLAN_QUANTITY
                    ,AVERAGE_DISCOUNT_PERCENTAGE,TOTAL_BORROWED_REVENUE,TOTAL_TP_REVENUE_IN,TOTAL_TP_REVENUE_OUT,TOTAL_REVENUE_ADJ
                    ,TOTAL_LENT_RESOURCE_COST,TOTAL_TP_COST_IN,TOTAL_TP_COST_OUT,TOTAL_COST_ADJ,TOTAL_UNASSIGNED_TIME_COST
                    ,TOTAL_UTILIZATION_PERCENT,TOTAL_UTILIZATION_HOURS,TOTAL_UTILIZATION_ADJ,TOTAL_CAPACITY,TOTAL_HEAD_COUNT
                    ,TOTAL_HEAD_COUNT_ADJ,RESOURCE_ASSIGNMENT_TYPE,TOTAL_PROJECT_RAW_COST,TOTAL_PROJECT_BURDENED_COST,TOTAL_PROJECT_REVENUE
                    ,PARENT_ASSIGNMENT_ID,WBS_ELEMENT_VERSION_ID,RBS_ELEMENT_ID,PLANNING_START_DATE,PLANNING_END_DATE
                    ,SPREAD_CURVE_ID,ETC_METHOD_CODE,RES_TYPE_CODE,ATTRIBUTE_CATEGORY,ATTRIBUTE1,ATTRIBUTE2,ATTRIBUTE3,ATTRIBUTE4,ATTRIBUTE5
                    ,ATTRIBUTE6,ATTRIBUTE7,ATTRIBUTE8,ATTRIBUTE9,ATTRIBUTE10,ATTRIBUTE11,ATTRIBUTE12,ATTRIBUTE13,ATTRIBUTE14,ATTRIBUTE15
                    ,ATTRIBUTE16,ATTRIBUTE17,ATTRIBUTE18,ATTRIBUTE19,ATTRIBUTE20,ATTRIBUTE21,ATTRIBUTE22,ATTRIBUTE23,ATTRIBUTE24,ATTRIBUTE25
                    ,ATTRIBUTE26,ATTRIBUTE27,ATTRIBUTE28,ATTRIBUTE29,ATTRIBUTE30,FC_RES_TYPE_CODE,RESOURCE_CLASS_CODE,ORGANIZATION_ID,JOB_ID
                    ,PERSON_ID,EXPENDITURE_TYPE,EXPENDITURE_CATEGORY,REVENUE_CATEGORY_CODE,EVENT_TYPE,SUPPLIER_ID,NON_LABOR_RESOURCE
                    ,BOM_RESOURCE_ID,INVENTORY_ITEM_ID,ITEM_CATEGORY_ID,RECORD_VERSION_NUMBER,BILLABLE_PERCENT
                    ,TRANSACTION_SOURCE_CODE,MFC_COST_TYPE_ID,PROCURE_RESOURCE_FLAG,ASSIGNMENT_DESCRIPTION
                    ,INCURRED_BY_RES_FLAG,RATE_JOB_ID,RATE_EXPENDITURE_TYPE,TA_DISPLAY_FLAG
                    ,SP_FIXED_DATE,PERSON_TYPE_CODE,RATE_BASED_FLAG,RESOURCE_RATE_BASED_FLAG            --IPM Arch Enhancement
                    ,USE_TASK_SCHEDULE_FLAG,RATE_EXP_FUNC_CURR_CODE
                    ,RATE_EXPENDITURE_ORG_ID,INCUR_BY_RES_CLASS_CODE,INCUR_BY_ROLE_ID
                    ,PROJECT_ROLE_ID,RESOURCE_CLASS_FLAG,NAMED_ROLE,TXN_ACCUM_HEADER_ID)
                 SELECT  L_targ_ra_id_tbl(kk)               -- RESOURCE_ASSIGNMENT_ID
                        ,p_budget_version_id                -- BUDGET_VERSION_ID
                        ,l_project_id                       -- PROJECT_ID
                        ,L_targ_task_id_tbl(kk)             -- TASK_ID
                        ,L_targ_rlm_id_tbl(kk)              -- RESOURCE_LIST_MEMBER_ID
                        ,sysdate                            -- LAST_UPDATE_DATE
                        ,fnd_global.user_id                 -- LAST_UPDATED_BY
                        ,sysdate                            -- CREATION_DATE
                        ,fnd_global.user_id                 -- CREATED_BY
                        ,fnd_global.login_id                -- LAST_UPDATE_LOGIN
                        ,l_targ_unit_of_measure_tbl(kk)     -- UNIT_OF_MEASURE
                        ,NULL                               -- TRACK_AS_LABOR_FLAG
                        ,NULL                               -- STANDARD_BILL_RATE
                        ,NULL                               -- AVERAGE_BILL_RATE
                        ,NULL                               -- AVERAGE_COST_RATE
                        ,-1                                 -- PROJECT_ASSIGNMENT_ID
                        ,NULL                               -- PLAN_ERROR_CODE
                        ,NULL                               -- TOTAL_PLAN_REVENUE
                        ,NULL                               -- TOTAL_PLAN_RAW_COST
                        ,NULL                               -- TOTAL_PLAN_BURDENED_COST
                        ,NULL                               -- TOTAL_PLAN_QUANTITY
                        ,NULL                               -- AVERAGE_DISCOUNT_PERCENTAGE
                        ,NULL                               -- TOTAL_BORROWED_REVENUE
                        ,NULL                               -- TOTAL_TP_REVENUE_IN
                        ,NULL                               -- TOTAL_TP_REVENUE_OUT
                        ,NULL                               -- TOTAL_REVENUE_ADJ
                        ,NULL                               -- TOTAL_LENT_RESOURCE_COST
                        ,NULL                               -- TOTAL_TP_COST_IN
                        ,NULL                               -- TOTAL_TP_COST_OUT
                        ,NULL                               -- TOTAL_COST_ADJ
                        ,NULL                               -- TOTAL_UNASSIGNED_TIME_COST
                        ,NULL                               -- TOTAL_UTILIZATION_PERCENT
                        ,NULL                               -- TOTAL_UTILIZATION_HOURS
                        ,NULL                               -- TOTAL_UTILIZATION_ADJ
                        ,NULL                               -- TOTAL_CAPACITY
                        ,NULL                               -- TOTAL_HEAD_COUNT
                        ,NULL                               -- TOTAL_HEAD_COUNT_ADJ
                        ,'USER_ENTERED'                     -- RESOURCE_ASSIGNMENT_TYPE
                        ,NULL                               -- TOTAL_PROJECT_RAW_COST
                        ,NULL                               -- TOTAL_PROJECT_BURDENED_COST
                        ,NULL                               -- TOTAL_PROJECT_REVENUE
                        ,NULL                               -- PARENT_ASSIGNMENT_ID
                        ,NULL                               -- WBS_ELEMENT_VERSION_ID
                        ,l_targ_rbs_element_id_tbl(kk)      -- RBS_ELEMENT_ID
                        ,l_planning_start_date_tbl(kk)      -- PLANNING_START_DATE
                        ,l_planning_end_date_tbl(kk)        -- PLANNING_END_DATE
                        ,l_targ_spread_curve_id_tbl(kk)     -- SPREAD_CURVE_ID
                        ,l_targ_etc_method_code_tbl(kk)     -- ETC_METHOD_CODE
                        ,l_targ_resource_type_code_tbl(kk)  -- RES_TYPE_CODE
                        ,NULL                               -- ATTRIBUTE_CATEGORY
                        ,NULL                               -- ATTRIBUTE1
                        ,NULL                               -- ATTRIBUTE2
                        ,NULL                               -- ATTRIBUTE3
                        ,NULL                               -- ATTRIBUTE4
                        ,NULL                               -- ATTRIBUTE5
                        ,NULL                               -- ATTRIBUTE6
                        ,NULL                               -- ATTRIBUTE7
                        ,NULL                               -- ATTRIBUTE8
                        ,NULL                               -- ATTRIBUTE9
                        ,NULL                               -- ATTRIBUTE10
                        ,NULL                               -- ATTRIBUTE11
                        ,NULL                               -- ATTRIBUTE12
                        ,NULL                               -- ATTRIBUTE13
                        ,NULL                               -- ATTRIBUTE14
                        ,NULL                               -- ATTRIBUTE15
                        ,NULL                               -- ATTRIBUTE16
                        ,NULL                               -- ATTRIBUTE17
                        ,NULL                               -- ATTRIBUTE18
                        ,NULL                               -- ATTRIBUTE19
                        ,NULL                               -- ATTRIBUTE20
                        ,NULL                               -- ATTRIBUTE21
                        ,NULL                               -- ATTRIBUTE22
                        ,NULL                               -- ATTRIBUTE23
                        ,NULL                               -- ATTRIBUTE24
                        ,NULL                               -- ATTRIBUTE25
                        ,NULL                               -- ATTRIBUTE26
                        ,NULL                               -- ATTRIBUTE27
                        ,NULL                               -- ATTRIBUTE28
                        ,NULL                               -- ATTRIBUTE29
                        ,NULL                               -- ATTRIBUTE30
                        ,l_targ_fc_res_type_code_tbl(kk)    -- FC_RES_TYPE_CODE
                        ,l_targ_resource_class_code_tbl(kk) -- RESOURCE_CLASS_CODE
                        ,l_targ_organization_id_tbl(kk)     -- ORGANIZATION_ID
                        ,l_targ_job_id_tbl(kk)              -- JOB_ID
                        ,l_targ_person_id_tbl(kk)           -- PERSON_ID
                        ,l_targ_expenditure_type_tbl(kk)    -- EXPENDITURE_TYPE
                        ,l_targ_expend_category_tbl(kk)     -- EXPENDITURE_CATEGORY
                        ,l_targ_rev_category_code_tbl(kk)   -- REVENUE_CATEGORY_CODE
                        ,l_targ_event_type_tbl(kk)          -- EVENT_TYPE
                        ,l_targ_supplier_id_tbl(kk)         -- SUPPLIER_ID
                        ,l_targ_non_labor_resource_tbl(kk)  -- NON_LABOR_RESOURCE
                        ,l_targ_bom_resource_id_tbl(kk)     -- BOM_RESOURCE_ID
                        ,l_targ_inventory_item_id_tbl(kk)   -- INVENTORY_ITEM_ID
                        ,l_targ_item_category_id_tbl(kk)    -- ITEM_CATEGORY_ID
                        ,1                                  -- RECORD_VERSION_NUMBER
                        ,NULL                               -- BILLABLE_PERCENT
                        , Decode(p_calling_context, null, null, -- BUG 3934574
                                  'BUDGET_GENERATION', 'CHANGE_DOCUMENTS',
                                  'FORECAST_GENERATION','CHANGE_DOCUMENTS') -- TRANSACTION_SOURCE_CODE
                        ,l_targ_mfc_cost_type_id_tbl(kk)    -- MFC_COST_TYPE_ID
                        ,NULL                               -- PROCURE_RESOURCE_FLAG
                        ,NULL                               -- ASSIGNMENT_DESCRIPTION
                        ,l_targ_incured_by_res_flag_tbl(kk) -- INCURRED_BY_RES_FLAG
                        ,NULL                               -- RATE_JOB_ID
                        ,l_targ_RATE_EXPEND_TYPE_tbl(kk)    -- RATE_EXPENDITURE_TYPE
                        ,NULL                               -- TA_DISPLAY_FLAG
                        ,NULL                               -- SP_FIXED_DATE
                        ,l_targ_person_type_code_tbl(kk)    -- PERSON_TYPE_CODE
                        ,l_targ_RATE_BASED_FLAG_tbl(kk)     -- RATE_BASED_FLAG
                        ,l_targ_RES_RATE_BASED_FLAG_tbl(kk) -- RESOURCE_RATE_BASED_FLAG IPM Arch Enhancement
                        ,NULL                               -- USE_TASK_SCHEDULE_FLAG
                        ,l_targ_RATE_EXP_FC_CUR_COD_tbl(kk) -- RATE_EXP_FUNC_CURR_CODE
                        ,l_targ_RATE_EXPEND_ORG_ID_tbl(kk)  -- RATE_EXPENDITURE_ORG_ID
                        ,l_targ_INCR_BY_RES_CLS_COD_tbl(kk) -- INCUR_BY_RES_CLASS_CODE
                        ,l_targ_INCUR_BY_ROLE_ID_tbl(kk)    -- INCUR_BY_ROLE_ID
                        ,l_targ_project_role_id_tbl(kk)     -- PROJECT_ROLE_ID
                        ,l_targ_RESOURCE_CLASS_FLAG_tbl(kk) -- RESOURCE_CLASS_FLAG
                        ,l_targ_NAMED_ROLE_tbl(kk)          -- NAMED_ROLE
                        ,l_targ_txn_accum_header_id_tbl(kk) -- TXN ACCUM HEADER ID
                 FROM    dual
                 WHERE  L_ra_dml_code_tbl(kk)='INSERT';
Line: 6074

                  pa_debug.g_err_stage:= 'Done with bulk insert into PRA';
Line: 6096

                UPDATE pa_resource_assignments pra
                SET    PLANNING_START_DATE         = l_planning_start_date_tbl(kk),
                       PLANNING_END_DATE           = l_planning_end_date_tbl(kk),
                       UNIT_OF_MEASURE             = l_targ_unit_of_measure_tbl(kk), -- bug 4171006
                       TRANSACTION_SOURCE_CODE     =
                          (SELECT DECODE(COUNT(*),0,'CHANGE_DOCUMENTS',TRANSACTION_SOURCE_CODE)
                           FROM pa_budget_lines pbl
                           WHERE  pbl.resource_assignment_id = pra.resource_assignment_id),
                       RATE_BASED_FLAG             = l_targ_RATE_BASED_FLAG_tbl(kk), -- bug 4171006
                       LAST_UPDATE_DATE            = sysdate,
                       LAST_UPDATED_BY             = fnd_global.user_id,
                       LAST_UPDATE_LOGIN           = fnd_global.login_id,
                       RECORD_VERSION_NUMBER       = NVL( RECORD_VERSION_NUMBER, 0 )  + 1
                WHERE  l_ra_dml_code_tbl (kk)= 'UPDATE' -- Bug 3662136
                AND    resource_assignment_id=l_targ_ra_id_tbl(kk)
                RETURNING
                task_id,
                rbs_element_id,
                resource_class_code,
                rate_based_flag,
                resource_assignment_id
                BULK COLLECT INTO
                l_upd_ra_task_id_tbl,
                l_upd_ra_rbs_elem_id_tbl,
                l_upd_ra_res_class_code_tbl,
                l_upd_ra_rbf_tbl,
                l_upd_ra_res_asmt_id_tbl;
Line: 6125

                UPDATE pa_resource_assignments pra
                SET    PLANNING_START_DATE         = l_planning_start_date_tbl(kk),
                       PLANNING_END_DATE           = l_planning_end_date_tbl(kk),
                       UNIT_OF_MEASURE             = l_targ_unit_of_measure_tbl(kk), -- bug 4171006
                       TRANSACTION_SOURCE_CODE     = null,
                       RATE_BASED_FLAG             = l_targ_RATE_BASED_FLAG_tbl(kk), -- bug 4171006
                       LAST_UPDATE_DATE            = sysdate,
                       LAST_UPDATED_BY             = fnd_global.user_id,
                       LAST_UPDATE_LOGIN           = fnd_global.login_id,
                       RECORD_VERSION_NUMBER       = NVL( RECORD_VERSION_NUMBER, 0 )  + 1
                WHERE  l_ra_dml_code_tbl (kk)= 'UPDATE' -- Bug 3662136
                AND    resource_assignment_id=l_targ_ra_id_tbl(kk)
                RETURNING
                task_id,
                rbs_element_id,
                resource_class_code,
                rate_based_flag,
                resource_assignment_id
                BULK COLLECT INTO
                l_upd_ra_task_id_tbl,
                l_upd_ra_rbs_elem_id_tbl,
                l_upd_ra_res_class_code_tbl,
                l_upd_ra_rbf_tbl,
                l_upd_ra_res_asmt_id_tbl;
Line: 6159

                    pa_debug.g_err_stage:= 'Done with bulk update of PRA';
Line: 6183

                          pa_debug.g_err_stage:= 'About to fire select for deriving params to calc API. Same Rls';
Line: 6188

                      SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id),
                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
                         DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
                      'N', --delete
                      'Y', --spread
                      decode(l_cost_impl_flag,'Y',pbls.quantity,decode(l_rev_impl_flag,'Y',
                                                              decode(l_impl_qty_tbl(j),'Y', nvl(pbls.quantity,0) * l_partial_factor,0),0)) + nvl(pblt.quantity,0), --total
                      Decode(l_cost_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.raw_cost,nvl(pbls.txn_raw_cost,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0),
                                                   nvl(pbls.project_raw_cost,nvl(pbls.txn_raw_cost,0)))),0) +
                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.raw_cost,nvl(pblt.txn_raw_cost,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_raw_cost,0),
                                                   nvl(pblt.project_raw_cost,nvl(pblt.txn_raw_cost,0)))) , --total
                      Decode(l_cost_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.burdened_cost,nvl(pbls.txn_burdened_cost,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                                                   nvl(pbls.project_burdened_cost,nvl(pbls.txn_burdened_cost,0)))),0) +
                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.burdened_cost,nvl(pblt.txn_burdened_cost,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_burdened_cost,0),
                                                   nvl(pblt.project_burdened_cost,nvl(pblt.txn_burdened_cost,0)))), --total
                      Decode(l_rev_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,nvl(pbls.txn_revenue,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                                                        nvl(pbls.project_revenue,nvl(pbls.txn_revenue,0)))),0)*l_partial_factor  +
                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.revenue,nvl(pblt.txn_revenue,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_revenue,0),
                                                        nvl(pblt.project_revenue,nvl(pblt.txn_revenue,0)))), --total
                      NULL,
                      NULL,
                      NULL
                      BULK COLLECT INTO
                      l_res_assignment_id_tbl,
                      l_currency_code_tbl,
                      l_delete_budget_lines_tbl,
                      l_spread_amount_flags_tbl,
                      l_total_quantity_tbl,
                      l_total_raw_cost_tbl,
                      l_total_burdened_cost_tbl,
                      l_total_revenue_tbl,
                      l_bl_TXN_COST_RATE_OVERIDE_tbl,
                      l_bl_BURDEN_COST_RAT_OVRID_tbl,
                      l_bl_TXN_BILL_RATE_OVERRID_tbl
                      from  (SELECT pra.resource_assignment_id resource_assignment_id,
                                    pra.task_id task_id,
                                    pra.resource_list_member_id resource_list_member_id,
                                    sum(quantity) quantity,
                                    sum(pbl.txn_raw_cost) txn_raw_cost,
                                    sum(pbl.txn_burdened_cost) txn_burdened_cost,
                                    sum(pbl.txn_revenue) txn_revenue,
                                    sum(pbl.project_raw_cost) project_raw_cost,
                                    sum(pbl.project_burdened_cost) project_burdened_cost,
                                    sum(pbl.project_revenue) project_revenue,
                                    sum(pbl.raw_cost) raw_cost,
                                    sum(pbl.burdened_cost) burdened_cost,
                                    sum(pbl.revenue) revenue,
                                    DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
                                           DECODE(l_same_multi_curr_flag,'Y', pbl.txn_currency_code,l_project_currency_code)) txn_currency_code
                             FROM   pa_budget_lines pbl,
                                    pa_resource_assignments pra
                             WHERE  pbl.resource_assignment_id = pra.resource_assignment_id
                             AND    pra.budget_version_id=l_src_ver_id_tbl(j)
                             GROUP BY pra.resource_assignment_id, pra.task_id, pra.resource_list_member_id,
                                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
                                             DECODE(l_same_multi_curr_flag,'Y', pbl.txn_currency_code,l_project_currency_code))  ) pbls,
                            (SELECT pbl.resource_assignment_id,
                                    sum(quantity) quantity,
                                    sum(pbl.txn_raw_cost) txn_raw_cost,
                                    sum(pbl.txn_burdened_cost) txn_burdened_cost,
                                    sum(pbl.txn_revenue) txn_revenue,
                                    sum(pbl.project_raw_cost) project_raw_cost,
                                    sum(pbl.project_burdened_cost) project_burdened_cost,
                                    sum(pbl.project_revenue) project_revenue,
                                    sum(pbl.raw_cost) raw_cost,
                                    sum(pbl.burdened_cost) burdened_cost,
                                    sum(pbl.revenue) revenue,
                                    pbl.txn_currency_code
                             FROM   pa_budget_lines pbl
                             WHERE  pbl.budget_Version_id = p_budget_version_id
                             GROUP BY pbl.resource_assignment_id, pbl.txn_currency_code)pblt
                      where get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id)=pblt.resource_assignment_id(+)
                      and   pblt.txn_Currency_code(+)= pbls.txn_currency_code;
Line: 6268

                          pa_debug.g_err_stage:= 'Done with select for deriving params to calc API. Same Rls';
Line: 6280

                      select get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id),
                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
                         DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
                      'N', --delete
                      'Y', --spread
                      decode(l_cost_impl_flag,'Y',pbls.quantity,decode(l_rev_impl_flag,'Y',
                                                              decode(l_impl_qty_tbl(j),'Y', nvl(pbls.quantity,0) * l_partial_factor,0),0)) +
                                                                     nvl(pblt.quantity,0), --total
                      Decode(l_cost_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.raw_cost,nvl(pbls.txn_raw_cost,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0),
                                                   nvl(pbls.project_raw_cost,nvl(pbls.txn_raw_cost,0)))),0) +
                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.raw_cost,nvl(pblt.txn_raw_cost,0)),
                                                DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_raw_cost,0),
                                                       nvl(pblt.project_raw_cost,nvl(pblt.txn_raw_cost,0)))), --total
                      Decode(l_cost_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.burdened_cost,nvl(pbls.txn_burdened_cost,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                                                   nvl(pbls.project_burdened_cost,nvl(pbls.txn_burdened_cost,0)))),0) +
                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.burdened_cost,nvl(pblt.txn_burdened_cost,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_burdened_cost,0),
                                                   nvl(pblt.project_burdened_cost,nvl(pblt.txn_burdened_cost,0)))), --total
                      Decode(l_rev_impl_flag ,'Y',DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,nvl(pbls.txn_revenue,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                                                        nvl(pbls.project_revenue,nvl(pbls.txn_revenue,0)))),0)*l_partial_factor +
                      DECODE(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pblt.revenue,nvl(pblt.txn_revenue,0)),
                                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pblt.txn_revenue,0),
                                                        nvl(pblt.project_revenue,nvl(pblt.txn_revenue,0)))),  --total
                      NULL,
                      NULL,
                      NULL
                      BULK COLLECT INTO
                      l_res_assignment_id_tbl,
                      l_currency_code_tbl,
                      l_delete_budget_lines_tbl,
                      l_spread_amount_flags_tbl,
                      l_total_quantity_tbl,
                      l_total_raw_cost_tbl,
                      l_total_burdened_cost_tbl,
                      l_total_revenue_tbl,
                      l_bl_TXN_COST_RATE_OVERIDE_tbl,
                      l_bl_BURDEN_COST_RAT_OVRID_tbl,
                      l_bl_TXN_BILL_RATE_OVERRID_tbl
                      from (SELECT pra.task_id task_id,
                                   tmp.resource_list_member_id resource_list_member_id,
                                   pra.resource_assignment_id resource_assignment_id,
                                   sum(quantity) quantity,
                                   sum(pbl.txn_raw_cost) txn_raw_cost,
                                   sum(pbl.txn_burdened_cost) txn_burdened_cost,
                                   sum(pbl.txn_revenue) txn_revenue,
                                   sum(pbl.project_raw_cost) project_raw_cost,
                                   sum(pbl.project_burdened_cost) project_burdened_cost,
                                   sum(pbl.project_revenue) project_revenue,
                                   sum(pbl.raw_cost) raw_cost,
                                   sum(pbl.burdened_cost) burdened_cost,
                                   sum(pbl.revenue) revenue,
                                   DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
                                          DECODE(l_same_multi_curr_flag,'Y', pbl.txn_currency_code,l_project_currency_code)) txn_currency_code
                            FROM   pa_resource_assignments pra
                                  ,pa_res_list_map_tmp4 tmp
                                  ,pa_budget_lines pbl
                            WHERE  pra.resource_assignment_id=tmp.txn_source_id
                            AND    pra.budget_version_id=l_src_ver_id_tbl(j)
                            AND    pbl.resource_assignment_id=pra.resource_assignment_id
                            GROUP BY pra.resource_assignment_id, pra.task_id, tmp.resource_list_member_id,
                                     DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,
                                          DECODE(l_same_multi_curr_flag,'Y', pbl.txn_currency_code,l_project_currency_code)) ) pbls,
                            (SELECT pbl.resource_assignment_id resource_assignment_id,
                                    sum(quantity) quantity,
                                    sum(pbl.txn_raw_cost) txn_raw_cost,
                                    sum(pbl.txn_burdened_cost) txn_burdened_cost,
                                    sum(pbl.txn_revenue) txn_revenue,
                                    sum(pbl.project_raw_cost) project_raw_cost,
                                    sum(pbl.project_burdened_cost) project_burdened_cost,
                                    sum(pbl.project_revenue) project_revenue,
                                    sum(pbl.raw_cost) raw_cost,
                                    sum(pbl.burdened_cost) burdened_cost,
                                    sum(pbl.revenue) revenue,
                                    pbl.txn_currency_code txn_currency_code
                             FROM   pa_budget_lines pbl
                             WHERE  pbl.budget_Version_id = p_budget_version_id
                             GROUP BY pbl.resource_assignment_id, pbl.txn_currency_code)pblt
                      where get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id)=pblt.resource_assignment_id(+)
                      and   pblt.txn_currency_code(+)= pbls.txn_currency_code;
Line: 6455

                              pa_debug.g_err_stage:= 'l_delete_budget_lines_tbl('||KK||') IS'||l_delete_budget_lines_tbl(kk);
Line: 6494

                     ,p_delete_budget_lines_tab    =>   l_delete_budget_lines_tbl
                     ,p_spread_amts_flag_tab       =>   l_spread_amount_flags_tbl
                     ,p_txn_currency_code_tab      =>   l_currency_code_tbl
                     ,p_total_qty_tab              =>   l_total_quantity_tbl
                     ,p_total_raw_cost_tab         =>   l_total_raw_cost_tbl -- dervie
                     ,p_total_burdened_cost_tab    =>   l_total_burdened_cost_tbl -- dervie
                     ,p_total_revenue_tab          =>   l_total_revenue_tbl -- derive
                     ,p_rw_cost_rate_override_tab  =>   l_bl_TXN_COST_RATE_OVERIDE_tbl
                     ,p_b_cost_rate_override_tab   =>   l_bl_BURDEN_COST_RAT_OVRID_tbl
                     ,p_bill_rate_override_tab     =>   l_bl_TXN_BILL_RATE_OVERRID_tbl
                     ,p_raTxn_rollup_api_call_flag =>   p_raTxn_rollup_api_call_flag --Indicates whether the pa_resource_asgn_curr maintenance api should be called
                     ,x_return_status              =>   l_return_status
                     ,x_msg_count                  =>   l_msg_count
                     ,x_msg_data                   =>   l_msg_data);
Line: 6526

                SELECT pa_budget_lines_s.nextval
                INTO   l_id_before_bl_insertion
                FROM   DUAL;
Line: 6536

                              pa_debug.g_err_stage:= 'About to bulk insert Budget lines with same RLs';
Line: 6542

                            INSERT INTO PA_BUDGET_LINES(
                                    RESOURCE_ASSIGNMENT_ID,
                                    START_DATE,
                                    LAST_UPDATE_DATE,
                                    LAST_UPDATED_BY,
                                    CREATION_DATE,
                                    CREATED_BY,
                                    LAST_UPDATE_LOGIN,
                                    END_DATE,
                                    PERIOD_NAME,
                                    QUANTITY,
                                    RAW_COST,
                                    BURDENED_COST,
                                    REVENUE,
                                    CHANGE_REASON_CODE,
                                    DESCRIPTION,
                                    ATTRIBUTE_CATEGORY,
                                    ATTRIBUTE1,
                                    ATTRIBUTE2,
                                    ATTRIBUTE3,
                                    ATTRIBUTE4,
                                    ATTRIBUTE5,
                                    ATTRIBUTE6,
                                    ATTRIBUTE7,
                                    ATTRIBUTE8,
                                    ATTRIBUTE9,
                                    ATTRIBUTE10,
                                    ATTRIBUTE11,
                                    ATTRIBUTE12,
                                    ATTRIBUTE13,
                                    ATTRIBUTE14,
                                    ATTRIBUTE15,
                                    RAW_COST_SOURCE,
                                    BURDENED_COST_SOURCE,
                                    QUANTITY_SOURCE,
                                    REVENUE_SOURCE,
                                    PM_PRODUCT_CODE,
                                    PM_BUDGET_LINE_REFERENCE,
                                    COST_REJECTION_CODE,
                                    REVENUE_REJECTION_CODE,
                                    BURDEN_REJECTION_CODE,
                                    OTHER_REJECTION_CODE,
                                    CODE_COMBINATION_ID,
                                    CCID_GEN_STATUS_CODE,
                                    CCID_GEN_REJ_MESSAGE,
                                    REQUEST_ID,
                                    BORROWED_REVENUE,
                                    TP_REVENUE_IN,
                                    TP_REVENUE_OUT,
                                    REVENUE_ADJ,
                                    LENT_RESOURCE_COST,
                                    TP_COST_IN,
                                    TP_COST_OUT,
                                    COST_ADJ,
                                    UNASSIGNED_TIME_COST,
                                    UTILIZATION_PERCENT,
                                    UTILIZATION_HOURS,
                                    UTILIZATION_ADJ,
                                    CAPACITY,
                                    HEAD_COUNT,
                                    HEAD_COUNT_ADJ,
                                    PROJFUNC_CURRENCY_CODE,
                                    PROJFUNC_COST_RATE_TYPE,
                                    PROJFUNC_COST_EXCHANGE_RATE,
                                    PROJFUNC_COST_RATE_DATE_TYPE,
                                    PROJFUNC_COST_RATE_DATE,
                                    PROJFUNC_REV_RATE_TYPE,
                                    PROJFUNC_REV_EXCHANGE_RATE,
                                    PROJFUNC_REV_RATE_DATE_TYPE,
                                    PROJFUNC_REV_RATE_DATE,
                                    PROJECT_CURRENCY_CODE,
                                    PROJECT_COST_RATE_TYPE,
                                    PROJECT_COST_EXCHANGE_RATE,
                                    PROJECT_COST_RATE_DATE_TYPE,
                                    PROJECT_COST_RATE_DATE,
                                    PROJECT_RAW_COST,
                                    PROJECT_BURDENED_COST,
                                    PROJECT_REV_RATE_TYPE,
                                    PROJECT_REV_EXCHANGE_RATE,
                                    PROJECT_REV_RATE_DATE_TYPE,
                                    PROJECT_REV_RATE_DATE,
                                    PROJECT_REVENUE,
                                    TXN_CURRENCY_CODE,
                                    TXN_RAW_COST,
                                    TXN_BURDENED_COST,
                                    TXN_REVENUE,
                                    BUCKETING_PERIOD_CODE,
                                    BUDGET_LINE_ID,
                                    BUDGET_VERSION_ID,
                                    TXN_STANDARD_COST_RATE,
                                    TXN_COST_RATE_OVERRIDE,
                                    COST_IND_COMPILED_SET_ID,
                          --            TXN_BURDEN_MULTIPLIER,
                          --            TXN_BURDEN_MULTIPLIER_OVERRIDE,
                                    TXN_STANDARD_BILL_RATE,
                                    TXN_BILL_RATE_OVERRIDE,
                                    TXN_MARKUP_PERCENT,
                                    TXN_MARKUP_PERCENT_OVERRIDE,
                                    TXN_DISCOUNT_PERCENTAGE,
                                    TRANSFER_PRICE_RATE,
                                    BURDEN_COST_RATE,
                                    BURDEN_COST_RATE_OVERRIDE,
                                    PC_CUR_CONV_REJECTION_CODE,
                                    PFC_CUR_CONV_REJECTION_CODE
                                    )
                              SELECT  pbl.resource_assignment_id,
                                    l_planning_start_date_tbl(kk) start_date,
                                    pbl.last_update_date,
                                    pbl.last_updated_by,
                                    pbl.creation_date,
                                    pbl.created_by,
                                    pbl.last_update_login,
                                    l_planning_end_date_tbl(kk) end_date,
                                    pbl.period_name,
                                    DECODE(l_targ_rate_based_flag_tbl(kk),
                                           'N',DECODE(l_target_version_type,
                                                      'REVENUE',pbl.txn_revenue
                                                               ,pbl.txn_raw_cost),
                                           pbl.quantity),
                                    pbl.raw_cost,
                                    pbl.burdened_cost,
                                    pbl.revenue,
                                    pbl.change_reason_code,
                                    pbl.description,
                                    pbl.attribute_category,
                                    pbl.attribute1,
                                    pbl.attribute2,
                                    pbl.attribute3,
                                    pbl.attribute4,
                                    pbl.attribute5,
                                    pbl.attribute6,
                                    pbl.attribute7,
                                    pbl.attribute8,
                                    pbl.attribute9,
                                    pbl.attribute10,
                                    pbl.attribute11,
                                    pbl.attribute12,
                                    pbl.attribute13,
                                    pbl.attribute14,
                                    pbl.attribute15,
                                    pbl.raw_cost_source,
                                    pbl.burdened_cost_source,
                                    pbl.quantity_source,
                                    pbl.revenue_source,
                                    pbl.pm_product_code,
                                    pbl.pm_budget_line_reference,
                                    pbl.cost_rejection_code,
                                    pbl.revenue_rejection_code,
                                    pbl.burden_rejection_code,
                                    pbl.other_rejection_code,
                                    pbl.code_combination_id,
                                    pbl.ccid_gen_status_code,
                                    pbl.ccid_gen_rej_message,
                                    pbl.request_id,
                                    pbl.borrowed_revenue,
                                    pbl.tp_revenue_in,
                                    pbl.tp_revenue_out,
                                    pbl.revenue_adj,
                                    pbl.lent_resource_cost,
                                    pbl.tp_cost_in,
                                    pbl.tp_cost_out,
                                    pbl.cost_adj,
                                    pbl.unassigned_time_cost,
                                    pbl.utilization_percent,
                                    pbl.utilization_hours,
                                    pbl.utilization_adj,
                                    pbl.capacity,
                                    pbl.head_count,
                                    pbl.head_count_adj,
                                    pbl.projfunc_currency_code,
                                    pbl.projfunc_cost_rate_type,
                                    DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y',
                                        Decode(decode(l_report_cost_using, 'R', nvl(pbl.txn_raw_cost,0),
                                                                  'B', nvl(pbl.txn_burdened_cost,0)),0,0,
                                            (decode(l_report_cost_using,'R',nvl(pbl.raw_cost,0),
                                                                  'B',nvl(pbl.burdened_cost,0)) /decode(l_report_cost_using,'R', pbl.txn_raw_cost,
                                                                                                            'B', pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
                                    pbl.projfunc_cost_rate_date_type,
                                    pbl.projfunc_cost_rate_date,
                                    pbl.projfunc_rev_rate_type,
                                    Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y',  Decode(nvl(pbl.txn_revenue,0),0,0,nvl(pbl.revenue,0) / pbl.txn_revenue),Null),Null), --Bug 3839273
                                    pbl.projfunc_rev_rate_date_type,
                                    pbl.projfunc_rev_rate_date,
                                    pbl.project_currency_code,
                                    pbl.project_cost_rate_type,
                                    DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
                                                                  'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.project_raw_cost,0),
                                                                         'B',nvl(pbl.project_burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
                                                                         'B',pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
                                    pbl.project_cost_rate_date_type,
                                    pbl.project_cost_rate_date,
                                    pbl.project_raw_cost,
                                    pbl.project_burdened_cost,
                                    pbl.project_rev_rate_type,
                                    Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,nvl(pbl.project_revenue,0) /pbl.txn_revenue),Null),Null), --Bug 3839273
                                    pbl.project_rev_rate_date_type,
                                    pbl.project_rev_rate_date,
                                    pbl.project_revenue,
                                    pbl.txn_currency_code,
                                    pbl.txn_raw_cost,
                                    pbl.txn_burdened_cost,
                                    pbl.txn_revenue,
                                    pbl.bucketing_period_code,
                                    pa_budget_lines_s.nextval,
                                    pbl.budget_version_id,
                                    pbl.txn_standard_cost_rate,
                                    DECODE(l_target_version_type,
                                         'REVENUE',pbl.txn_cost_rate_override,
                                          DECODE(l_targ_rate_based_flag_tbl(kk),
                                                'N',1,
                                                pbl.txn_cost_rate_override)),
                                    pbl.cost_ind_compiled_set_id,
                          --          pbl.  txn_burden_multiplier,
                          --          pbl.  txn_burden_multiplier_override,
                                    pbl.txn_standard_bill_rate,
                                    DECODE(l_target_version_type,
                                           'REVENUE',DECODE(l_targ_rate_based_flag_tbl(kk),
                                                            'N',1,
                                                            pbl.txn_bill_rate_override)
                                           ,pbl.txn_bill_rate_override),
                                    pbl.txn_markup_percent,
                                    pbl.txn_markup_percent_override,
                                    pbl.txn_discount_percentage,
                                    pbl.transfer_price_rate,
                                    pbl.burden_cost_rate,
                                    DECODE(l_target_version_type,
                                         'REVENUE',pbl.burden_cost_rate_override,
                                          DECODE(l_targ_rate_based_flag_tbl(kk),
                                                'Y',pbl.burden_cost_rate_override,
                                                 DECODE(nvl(pbl.txn_raw_cost,0),
                                                        0,null,
                                                        pbl.txn_burdened_cost/pbl.txn_raw_cost))),
                                    pbl.pc_cur_conv_rejection_code,
                                    pbl.pfc_cur_conv_rejection_code
                              FROM
                                 --The entire SELECT is moved to the sub query in FROM clause as nextval would not work with group by
                                (SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id), pras.resource_list_member_id) resource_assignment_id,
                                   sysdate last_update_date,
                                   fnd_global.user_id last_updated_by,
                                   sysdate creation_date,
                                   fnd_global.user_id created_by,
                                   fnd_global.login_id last_update_login,
                                   NULL period_name,
                                   decode(l_cost_impl_flag,
                                             'Y',sum(pbls.quantity),
                                             decode(l_rev_impl_flag,
                                                      'Y',decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),
                                                      null)) quantity,
                                   sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)) raw_cost,
                                   sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)) burdened_cost,
                                   sum(Decode(l_rev_impl_flag ,'Y',  pbls.revenue,null))*l_partial_factor revenue,
                                   decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null) change_reason_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.description),null) description,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null) attribute_category,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null) attribute1,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null) attribute2,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null) attribute3,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null) attribute4,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null) attribute5,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null) attribute6,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null) attribute7,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null) attribute8,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null) attribute9,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null) attribute10,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null) attribute11,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null) attribute12,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null) attribute13,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null) attribute14,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null) attribute15,
                                   'I' raw_cost_source,
                                   'I' burdened_cost_source,
                                   'I' quantity_source,
                                   'I' revenue_source,
                                   decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null) pm_product_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null) pm_budget_line_reference,
                                   decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null) cost_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null) revenue_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null) burden_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null)other_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null) code_combination_id,
                                   decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null) ccid_gen_status_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null) ccid_gen_rej_message,
                                   decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null) request_id,
                                   decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null) borrowed_revenue,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null) tp_revenue_in,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null) tp_revenue_out,
                                   decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null) revenue_adj,
                                   decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null) lent_resource_cost,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null) tp_cost_in,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null) tp_cost_out,
                                   decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null) cost_adj,
                                   decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null) unassigned_time_cost,
                                   decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null) utilization_percent,
                                   decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null) utilization_hours,
                                   decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null) utilization_adj,
                                   decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null) capacity,
                                   decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null) head_count,
                                   decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null) head_count_adj,
                                   l_projfunc_currency_code projfunc_currency_code,
                                   DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_cost_rate_type,
                                   null projfunc_cost_exchange_rate, --Bug 3839273
                                   null projfunc_cost_rate_date_type,
                                   null projfunc_cost_rate_date,
                                   Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_rev_rate_type,
                                   null projfunc_rev_exchange_rate, --Bug 3839273
                                   null projfunc_rev_rate_date_type,
                                   null projfunc_rev_rate_date,
                                   l_project_currency_code project_currency_code ,
                                   DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null) project_cost_rate_type,
                                   null project_cost_exchange_rate, --Bug 3839273
                                   null project_cost_rate_date_type,
                                   null project_cost_rate_date,
                                   sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)) project_raw_cost,
                                   sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)) project_burdened_cost,
                                   Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null) project_rev_rate_type,
                                   null project_rev_exchange_rate, --Bug 3839273
                                   null project_rev_rate_date_type,
                                   null project_rev_rate_date,
                                   sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor project_revenue,
                                   DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)) txn_currency_code,

                                   --Bug 4224757. Code changes for bug#4224757 starts here
                                   SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0)))))
                                   txn_raw_cost,
                                   SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                                   nvl(pbls.project_burdened_cost,0))))) txn_burdened_cost,
                                   SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                                   nvl(pbls.project_revenue,0)))))*l_partial_factor txn_revenue,
                                   --Bug 4224757.. Code changes for bug#4224757 ends here

                                   null bucketing_period_code,
                                   p_budget_version_id  budget_version_id,
                                   decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null) txn_standard_cost_rate,

                                   --Bug 4224757. Code changes for bug#4224757 starts here
                                   decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                                   decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                                   nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
                                   decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                        decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))     txn_cost_rate_override,
                                   --Bug 4224757. Code changes for bug#4224757 ends here




                                   decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null) cost_ind_compiled_set_id,
                               --      decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),
                                   decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null) txn_standard_bill_rate ,

                                   --Bug 4224757. Code changes for bug#4224757 starts here
                                   decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
                                          decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
                                          'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
                                   decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                        decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))txn_bill_rate_override,
                                   --Bug 4224757. Code changes for bug#4224757 ends here

                                   decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null)   txn_markup_percent,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null) txn_markup_percent_override,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null)   txn_discount_percentage,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null) transfer_price_rate,
                                   decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null) burden_cost_rate,

                                   --Bug 4224757. Code changes for bug#4224757 starts here
                                   decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                                   decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag,
                                   'Y', nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
                                   decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                        decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) burden_cost_rate_override,
                                   --Bug 4224757. Code changes for bug#4224757 ends here



                                   decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null) pc_cur_conv_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null) pfc_cur_conv_rejection_code
                              from   pa_budget_lines pbls,
                                   pa_resource_assignments pras
                              where  l_ra_dml_code_tbl(kk)='INSERT'
                              and    pras.resource_assignment_id = pbls.resource_assignment_id
                              and    pras.budget_version_id = l_src_ver_id_tbl(j)
                              and    PA_FP_CI_MERGE.get_mapped_ra_id(PA_FP_CI_MERGE.get_task_id(l_targ_plan_level_code,pras.task_id), pras.resource_list_member_id)= L_targ_ra_id_tbl(kk)
                               --IPM Arch Enhancement Bug 4865563
                              /*and    pbls.cost_rejection_code IS NULL
                              and    pbls.revenue_rejection_code IS NULL
                              and    pbls.burden_rejection_code IS NULL
                              and    pbls.other_rejection_code IS NULL
                              and    pbls.pc_cur_conv_rejection_code IS NULL
                              and    pbls.pfc_cur_conv_rejection_code IS NULL*/
                              GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id),pras.resource_list_member_id) ,
                                     DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code)))pbl;
Line: 6937

                              pa_debug.g_err_stage:= 'After bulk-inserting resource assignments';
Line: 6945

                          pa_debug.g_err_stage:= 'About to bulk insert Budget lines with diff RLs and with targ TP as None';
Line: 6951

                      INSERT INTO PA_BUDGET_LINES(RESOURCE_ASSIGNMENT_ID,
                               START_DATE,
                               LAST_UPDATE_DATE,
                               LAST_UPDATED_BY,
                               CREATION_DATE,
                               CREATED_BY,
                               LAST_UPDATE_LOGIN,
                               END_DATE,
                               PERIOD_NAME,
                               QUANTITY,
                               RAW_COST,
                               BURDENED_COST,
                               REVENUE,
                               CHANGE_REASON_CODE,
                               DESCRIPTION,
                               ATTRIBUTE_CATEGORY,
                               ATTRIBUTE1,
                               ATTRIBUTE2,
                               ATTRIBUTE3,
                               ATTRIBUTE4,
                               ATTRIBUTE5,
                               ATTRIBUTE6,
                               ATTRIBUTE7,
                               ATTRIBUTE8,
                               ATTRIBUTE9,
                               ATTRIBUTE10,
                               ATTRIBUTE11,
                               ATTRIBUTE12,
                               ATTRIBUTE13,
                               ATTRIBUTE14,
                               ATTRIBUTE15,
                               RAW_COST_SOURCE,
                               BURDENED_COST_SOURCE,
                               QUANTITY_SOURCE,
                               REVENUE_SOURCE,
                               PM_PRODUCT_CODE,
                               PM_BUDGET_LINE_REFERENCE,
                               COST_REJECTION_CODE,
                               REVENUE_REJECTION_CODE,
                               BURDEN_REJECTION_CODE,
                               OTHER_REJECTION_CODE,
                               CODE_COMBINATION_ID,
                               CCID_GEN_STATUS_CODE,
                               CCID_GEN_REJ_MESSAGE,
                               REQUEST_ID,
                               BORROWED_REVENUE,
                               TP_REVENUE_IN,
                               TP_REVENUE_OUT,
                               REVENUE_ADJ,
                               LENT_RESOURCE_COST,
                               TP_COST_IN,
                               TP_COST_OUT,
                               COST_ADJ,
                               UNASSIGNED_TIME_COST,
                               UTILIZATION_PERCENT,
                               UTILIZATION_HOURS,
                               UTILIZATION_ADJ,
                               CAPACITY,
                               HEAD_COUNT,
                               HEAD_COUNT_ADJ,
                               PROJFUNC_CURRENCY_CODE,
                               PROJFUNC_COST_RATE_TYPE,
                               PROJFUNC_COST_EXCHANGE_RATE,
                               PROJFUNC_COST_RATE_DATE_TYPE,
                               PROJFUNC_COST_RATE_DATE,
                               PROJFUNC_REV_RATE_TYPE,
                               PROJFUNC_REV_EXCHANGE_RATE,
                               PROJFUNC_REV_RATE_DATE_TYPE,
                               PROJFUNC_REV_RATE_DATE,
                               PROJECT_CURRENCY_CODE,
                               PROJECT_COST_RATE_TYPE,
                               PROJECT_COST_EXCHANGE_RATE,
                               PROJECT_COST_RATE_DATE_TYPE,
                               PROJECT_COST_RATE_DATE,
                               PROJECT_RAW_COST,
                               PROJECT_BURDENED_COST,
                               PROJECT_REV_RATE_TYPE,
                               PROJECT_REV_EXCHANGE_RATE,
                               PROJECT_REV_RATE_DATE_TYPE,
                               PROJECT_REV_RATE_DATE,
                               PROJECT_REVENUE,
                               TXN_CURRENCY_CODE,
                               TXN_RAW_COST,
                               TXN_BURDENED_COST,
                               TXN_REVENUE,
                               BUCKETING_PERIOD_CODE,
                               BUDGET_LINE_ID,
                               BUDGET_VERSION_ID,
                               TXN_STANDARD_COST_RATE,
                               TXN_COST_RATE_OVERRIDE,
                               COST_IND_COMPILED_SET_ID,
                        --           TXN_BURDEN_MULTIPLIER,
                        --           TXN_BURDEN_MULTIPLIER_OVERRIDE,
                               TXN_STANDARD_BILL_RATE,
                               TXN_BILL_RATE_OVERRIDE,
                               TXN_MARKUP_PERCENT,
                               TXN_MARKUP_PERCENT_OVERRIDE,
                               TXN_DISCOUNT_PERCENTAGE,
                               TRANSFER_PRICE_RATE,
                               BURDEN_COST_RATE,
                               BURDEN_COST_RATE_OVERRIDE,
                               PC_CUR_CONV_REJECTION_CODE,
                               PFC_CUR_CONV_REJECTION_CODE
                               )
                        SELECT  pbl.resource_assignment_id,
                              l_planning_start_date_tbl(kk) start_date,
                              pbl.last_update_date,
                              pbl.last_updated_by,
                              pbl.creation_date,
                              pbl.created_by,
                              pbl.last_update_login,
                              l_planning_end_date_tbl(kk) end_date,
                              pbl.period_name,
                              DECODE(l_targ_rate_based_flag_tbl(kk),
                                     'N',DECODE(l_target_version_type,
                                                'REVENUE',pbl.txn_revenue
                                                         ,pbl.txn_raw_cost),
                                      pbl.quantity),
                              pbl.raw_cost,
                              pbl.burdened_cost,
                              pbl.revenue,
                              pbl.change_reason_code,
                              pbl.description,
                              pbl.attribute_category,
                              pbl.attribute1,
                              pbl.attribute2,
                              pbl.attribute3,
                              pbl.attribute4,
                              pbl.attribute5,
                              pbl.attribute6,
                              pbl.attribute7,
                              pbl.attribute8,
                              pbl.attribute9,
                              pbl.attribute10,
                              pbl.attribute11,
                              pbl.attribute12,
                              pbl.attribute13,
                              pbl.attribute14,
                              pbl.attribute15,
                              pbl.raw_cost_source,
                              pbl.burdened_cost_source,
                              pbl.quantity_source,
                              pbl.revenue_source,
                              pbl.pm_product_code,
                              pbl.pm_budget_line_reference,
                              pbl.cost_rejection_code,
                              pbl.revenue_rejection_code,
                              pbl.burden_rejection_code,
                              pbl.other_rejection_code,
                              pbl.code_combination_id,
                              pbl.ccid_gen_status_code,
                              pbl.ccid_gen_rej_message,
                              pbl.request_id,
                              pbl.borrowed_revenue,
                              pbl.tp_revenue_in,
                              pbl.tp_revenue_out,
                              pbl.revenue_adj,
                              pbl.lent_resource_cost,
                              pbl.tp_cost_in,
                              pbl.tp_cost_out,
                              pbl.cost_adj,
                              pbl.unassigned_time_cost,
                              pbl.utilization_percent,
                              pbl.utilization_hours,
                              pbl.utilization_adj,
                              pbl.capacity,
                              pbl.head_count,
                              pbl.head_count_adj,
                              pbl.projfunc_currency_code,
                              pbl.projfunc_cost_rate_type,
                              DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
                                              'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.raw_cost,0),
                                              'B',nvl(pbl.burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
                                              'B', pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
                              pbl.projfunc_cost_rate_date_type,
                              pbl.projfunc_cost_rate_date,
                              pbl.projfunc_rev_rate_type,
                              Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y',  Decode(nvl(pbl.txn_revenue,0),0,0,nvl(pbl.revenue,0) /pbl.txn_revenue),Null),Null), --Bug 3839273
                              pbl.projfunc_rev_rate_date_type,
                              pbl.projfunc_rev_rate_date,
                              pbl.project_currency_code,
                              pbl.project_cost_rate_type,
                              DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
                                               'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.project_raw_cost,0),
                                               'B',nvl(pbl.project_burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
                                               'B',pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
                              pbl.project_cost_rate_date_type,
                              pbl.project_cost_rate_date,
                              pbl.project_raw_cost,
                              pbl.project_burdened_cost,
                              pbl.project_rev_rate_type,
                              Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.project_revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
                              pbl.project_rev_rate_date_type,
                              pbl.project_rev_rate_date,
                              pbl.project_revenue,
                              pbl.txn_currency_code,
                              pbl.txn_raw_cost,
                              pbl.txn_burdened_cost,
                              pbl.txn_revenue,
                              pbl.bucketing_period_code,
                              pa_budget_lines_s.nextval,
                              pbl.budget_version_id,
                              pbl.txn_standard_cost_rate,
                              DECODE(l_target_version_type,
                                   'REVENUE',pbl.txn_cost_rate_override,
                                    DECODE(l_targ_rate_based_flag_tbl(kk),
                                           'N',1,
                                           pbl.txn_cost_rate_override)),
                              pbl.cost_ind_compiled_set_id,
                    --          pbl.  txn_burden_multiplier,
                    --          pbl.  txn_burden_multiplier_override,
                              pbl.txn_standard_bill_rate,
                              DECODE(l_target_version_type,
                                     'REVENUE',DECODE(l_targ_rate_based_flag_tbl(kk),
                                                      'N',1,
                                                      pbl.txn_bill_rate_override),
                                     pbl.txn_bill_rate_override),
                              pbl.txn_markup_percent,
                              pbl.txn_markup_percent_override,
                              pbl.txn_discount_percentage,
                              pbl.transfer_price_rate,
                              pbl.burden_cost_rate,
                              DECODE(l_target_version_type,
                                   'REVENUE',pbl.burden_cost_rate_override,
                                    DECODE(l_targ_rate_based_flag_tbl(kk),
                                          'Y',pbl.burden_cost_rate_override,
                                          DECODE(nvl(pbl.txn_raw_cost,0),
                                                 0,null,
                                                 pbl.txn_burdened_cost/pbl.txn_raw_cost))),
                              pbl.pc_cur_conv_rejection_code,
                              pbl.pfc_cur_conv_rejection_code
                        FROM
                                 --The entier SELECT is moved to the sub query in FROM clause as nextval would not work with group by
                         (SELECT pa_fp_ci_merge.get_mapped_ra_id(pa_fp_ci_merge.get_task_id(l_targ_plan_level_code,pras.task_id), rlmap.resource_list_member_id) resource_assignment_id,
                              sysdate    last_update_date,
                              fnd_global.user_id  last_updated_by,
                              sysdate  creation_date,
                              fnd_global.user_id  created_by,
                              fnd_global.login_id last_update_login,
                              NULL period_name,
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                   decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)) quantity,
                              sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)) raw_cost,
                              sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)) burdened_cost,
                              sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue,null))*l_partial_factor revenue,
                              decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null) change_reason_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.description),null) description,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null) attribute_category,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null)   attribute1 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null)   attribute2 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null)   attribute3 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null)   attribute4 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null)   attribute5 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null)   attribute6 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null)   attribute7 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null)   attribute8 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null)   attribute9 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null)attribute10 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null)attribute11 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null)attribute12 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null)attribute13 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null)attribute14 ,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null)attribute15 ,
                              'I' raw_cost_source     ,
                              'I' burdened_cost_source,
                              'I' quantity_source     ,
                              'I' revenue_source      ,
                              decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null) pm_product_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null) pm_budget_line_reference,
                              decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null) cost_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null) revenue_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null) burden_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null) other_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null) code_combination_id,
                              decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null) ccid_gen_status_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null) ccid_gen_rej_message,
                              decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null) request_id,
                              decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null) borrowed_revenue,
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null) tp_revenue_in,
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null) tp_revenue_out,
                              decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null)revenue_adj,
                              decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null) lent_resource_cost,
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null) tp_cost_in,
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null) tp_cost_out,
                              decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null) cost_adj,
                              decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null) unassigned_time_cost,
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null) utilization_percent,
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null) utilization_hours,
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null) utilization_adj,
                              decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null) capacity,
                              decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null) head_count,
                              decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null) head_count_adj,
                              l_projfunc_currency_code projfunc_currency_code,
                              DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_cost_rate_type,
                              null projfunc_cost_exchange_rate, --Bug 3839273
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null) projfunc_cost_rate_date_type,
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null) projfunc_cost_rate_date,
                              Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_rev_rate_type,
                              null projfunc_rev_exchange_rate, --Bug 3839273
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null) projfunc_rev_rate_date_type,
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null) projfunc_rev_rate_date,
                              l_project_currency_code project_currency_code,
                              DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null) project_cost_rate_type,
                              null project_cost_exchange_rate, --Bug 3839273
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null) project_cost_rate_date_type,
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null) project_cost_rate_date,
                              sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)) project_raw_cost,
                              sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)) project_burdened_cost,
                              Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null) project_rev_rate_type,
                              null project_rev_exchange_rate, --Bug 3839273
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null) project_rev_rate_date_type,
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null) project_rev_rate_date,
                              sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor project_revenue,
                              DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)) txn_currency_code,

                              --Bug 4224757.. Code changes for bug#4224757 starts here
                              SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0)))))
                              txn_raw_cost,
                              SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                              nvl(pbls.project_burdened_cost,0))))) txn_burdened_cost,
                              SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                              nvl(pbls.project_revenue,0)))))*l_partial_factor txn_revenue,
                              --Bug 4224757.. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null) bucketing_period_code,
                              p_budget_version_id budget_version_id,
                              decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null) txn_standard_cost_rate,

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                              decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                               nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                  decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))     txn_cost_rate_override,
                              --Bug 4224757. Code changes for bug#4224757 ends here



                              decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null) cost_ind_compiled_set_id,
                        --        decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),

                              decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null) txn_standard_bill_rate,

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
                                   decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
                                     'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
                                     decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                   decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_bill_rate_override,
                              --Bug 4224757. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null) txn_markup_percent,
                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null) txn_markup_percent_override,
                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null) txn_discount_percentage,
                              decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null) transfer_price_rate,
                              decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null) burden_cost_rate,

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                              decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                                nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                               decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) burden_cost_rate_override,
                              --Bug 4224757. Code changes for bug#4224757 ends here



                              decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null) pc_cur_conv_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null) pfc_cur_conv_rejection_code
                         from   pa_budget_lines pbls,
                              pa_resource_assignments pras,
                              pa_res_list_map_tmp4  rlmap
                         where  l_ra_dml_code_tbl(kk)='INSERT'
                         and    pras.resource_assignment_id = pbls.resource_assignment_id
                         and    pras.budget_version_id = l_src_ver_id_tbl(j)
                         AND    pras.resource_assignment_id=rlmap.txn_source_id
                         and    pa_fp_ci_merge.get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id), rlmap.resource_list_member_id)=l_targ_ra_id_tbl(kk)
                            --IPM Arch Enhancement Bug 4865563
                       /*and    pbls.cost_rejection_code IS NULL
                         and    pbls.revenue_rejection_code IS NULL
                         and    pbls.burden_rejection_code IS NULL
                         and    pbls.other_rejection_code IS NULL
                         and    pbls.pc_cur_conv_rejection_code IS NULL
                         and    pbls.pfc_cur_conv_rejection_code IS NULL*/
                         GROUP BY pa_fp_ci_merge.get_mapped_ra_id(pa_fp_ci_merge.get_task_id(l_targ_plan_level_code,pras.task_id),rlmap.resource_list_member_id) ,
                                DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code)))pbl;
Line: 7342

                              pa_debug.g_err_stage:= 'Done with bulk insert Budget lines with diff RLs and with targ TP as None';
Line: 7350

                        pa_debug.g_err_stage:= 'SRC tp =targ TP. same RLS. About to bulk insert BLs';
Line: 7357

                         INSERT INTO PA_BUDGET_LINES(
                                    RESOURCE_ASSIGNMENT_ID,
                                    START_DATE,
                                    LAST_UPDATE_DATE,
                                    LAST_UPDATED_BY,
                                    CREATION_DATE,
                                    CREATED_BY,
                                    LAST_UPDATE_LOGIN,
                                    END_DATE,
                                    PERIOD_NAME,
                                    QUANTITY,
                                    RAW_COST,
                                    BURDENED_COST,
                                    REVENUE,
                                    CHANGE_REASON_CODE,
                                    DESCRIPTION,
                                    ATTRIBUTE_CATEGORY,
                                    ATTRIBUTE1,
                                    ATTRIBUTE2,
                                    ATTRIBUTE3,
                                    ATTRIBUTE4,
                                    ATTRIBUTE5,
                                    ATTRIBUTE6,
                                    ATTRIBUTE7,
                                    ATTRIBUTE8,
                                    ATTRIBUTE9,
                                    ATTRIBUTE10,
                                    ATTRIBUTE11,
                                    ATTRIBUTE12,
                                    ATTRIBUTE13,
                                    ATTRIBUTE14,
                                    ATTRIBUTE15,
                                    RAW_COST_SOURCE,
                                    BURDENED_COST_SOURCE,
                                    QUANTITY_SOURCE,
                                    REVENUE_SOURCE,
                                    PM_PRODUCT_CODE,
                                    PM_BUDGET_LINE_REFERENCE,
                                    COST_REJECTION_CODE,
                                    REVENUE_REJECTION_CODE,
                                    BURDEN_REJECTION_CODE,
                                    OTHER_REJECTION_CODE,
                                    CODE_COMBINATION_ID,
                                    CCID_GEN_STATUS_CODE,
                                    CCID_GEN_REJ_MESSAGE,
                                    REQUEST_ID,
                                    BORROWED_REVENUE,
                                    TP_REVENUE_IN,
                                    TP_REVENUE_OUT,
                                    REVENUE_ADJ,
                                    LENT_RESOURCE_COST,
                                    TP_COST_IN,
                                    TP_COST_OUT,
                                    COST_ADJ,
                                    UNASSIGNED_TIME_COST,
                                    UTILIZATION_PERCENT,
                                    UTILIZATION_HOURS,
                                    UTILIZATION_ADJ,
                                    CAPACITY,
                                    HEAD_COUNT,
                                    HEAD_COUNT_ADJ,
                                    PROJFUNC_CURRENCY_CODE,
                                    PROJFUNC_COST_RATE_TYPE,
                                    PROJFUNC_COST_EXCHANGE_RATE,
                                    PROJFUNC_COST_RATE_DATE_TYPE,
                                    PROJFUNC_COST_RATE_DATE,
                                    PROJFUNC_REV_RATE_TYPE,
                                    PROJFUNC_REV_EXCHANGE_RATE,
                                    PROJFUNC_REV_RATE_DATE_TYPE,
                                    PROJFUNC_REV_RATE_DATE,
                                    PROJECT_CURRENCY_CODE,
                                    PROJECT_COST_RATE_TYPE,
                                    PROJECT_COST_EXCHANGE_RATE,
                                    PROJECT_COST_RATE_DATE_TYPE,
                                    PROJECT_COST_RATE_DATE,
                                    PROJECT_RAW_COST,
                                    PROJECT_BURDENED_COST,
                                    PROJECT_REV_RATE_TYPE,
                                    PROJECT_REV_EXCHANGE_RATE,
                                    PROJECT_REV_RATE_DATE_TYPE,
                                    PROJECT_REV_RATE_DATE,
                                    PROJECT_REVENUE,
                                    TXN_CURRENCY_CODE,
                                    TXN_RAW_COST,
                                    TXN_BURDENED_COST,
                                    TXN_REVENUE,
                                    BUCKETING_PERIOD_CODE,
                                    BUDGET_LINE_ID,
                                    BUDGET_VERSION_ID,
                                    TXN_STANDARD_COST_RATE,
                                    TXN_COST_RATE_OVERRIDE,
                                    COST_IND_COMPILED_SET_ID,
                             --         TXN_BURDEN_MULTIPLIER,
                             --         TXN_BURDEN_MULTIPLIER_OVERRIDE,
                                    TXN_STANDARD_BILL_RATE,
                                    TXN_BILL_RATE_OVERRIDE,
                                    TXN_MARKUP_PERCENT,
                                    TXN_MARKUP_PERCENT_OVERRIDE,
                                    TXN_DISCOUNT_PERCENTAGE,
                                    TRANSFER_PRICE_RATE,
                                    BURDEN_COST_RATE,
                                    BURDEN_COST_RATE_OVERRIDE,
                                    PC_CUR_CONV_REJECTION_CODE,
                                    PFC_CUR_CONV_REJECTION_CODE
                                    )
                         SELECT       pbl.resource_assignment_id,
                                    pbl.start_date,
                                    pbl.last_update_date,
                                    pbl.last_updated_by,
                                    pbl.creation_date,
                                    pbl.created_by,
                                    pbl.last_update_login,
                                    pbl.end_date,
                                    pbl.period_name,
                                    DECODE(l_targ_rate_based_flag_tbl(kk),
                                           'N',DECODE(l_target_version_type,
                                                      'REVENUE',pbl.txn_revenue
                                                               ,pbl.txn_raw_cost),
                                           pbl.quantity),
                                    pbl.raw_cost,
                                    pbl.burdened_cost,
                                    pbl.revenue,
                                    pbl.change_reason_code,
                                    pbl.description,
                                    pbl.attribute_category,
                                    pbl.attribute1,
                                    pbl.attribute2,
                                    pbl.attribute3,
                                    pbl.attribute4,
                                    pbl.attribute5,
                                    pbl.attribute6,
                                    pbl.attribute7,
                                    pbl.attribute8,
                                    pbl.attribute9,
                                    pbl.attribute10,
                                    pbl.attribute11,
                                    pbl.attribute12,
                                    pbl.attribute13,
                                    pbl.attribute14,
                                    pbl.attribute15,
                                    pbl.raw_cost_source,
                                    pbl.burdened_cost_source,
                                    pbl.quantity_source,
                                    pbl.revenue_source,
                                    pbl.pm_product_code,
                                    pbl.pm_budget_line_reference,
                                    pbl.cost_rejection_code,
                                    pbl.revenue_rejection_code,
                                    pbl.burden_rejection_code,
                                    pbl.other_rejection_code,
                                    pbl.code_combination_id,
                                    pbl.ccid_gen_status_code,
                                    pbl.ccid_gen_rej_message,
                                    pbl.request_id,
                                    pbl.borrowed_revenue,
                                    pbl.tp_revenue_in,
                                    pbl.tp_revenue_out,
                                    pbl.revenue_adj,
                                    pbl.lent_resource_cost,
                                    pbl.tp_cost_in,
                                    pbl.tp_cost_out,
                                    pbl.cost_adj,
                                    pbl.unassigned_time_cost,
                                    pbl.utilization_percent,
                                    pbl.utilization_hours,
                                    pbl.utilization_adj,
                                    pbl.capacity,
                                    pbl.head_count,
                                    pbl.head_count_adj,
                                    pbl.projfunc_currency_code,
                                    pbl.projfunc_cost_rate_type,
                                    DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
                                                     'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.raw_cost,0),
                                                     'B',nvl(pbl.burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
                                                     'B', pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
                                    pbl.projfunc_cost_rate_date_type,
                                    pbl.projfunc_cost_rate_date,
                                    pbl.projfunc_rev_rate_type,
                                    Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y',  Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
                                    pbl.projfunc_rev_rate_date_type,
                                    pbl.projfunc_rev_rate_date,
                                    pbl.project_currency_code,
                                    pbl.project_cost_rate_type,
                                    DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
                                                                   'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.project_raw_cost,0),
                                                                   'B',nvl(pbl.project_burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
                                                                   'B',pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
                                    pbl.project_cost_rate_date_type,
                                    pbl.project_cost_rate_date,
                                    pbl.project_raw_cost,
                                    pbl.project_burdened_cost,
                                    pbl.project_rev_rate_type,
                                    Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.project_revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
                                    pbl.project_rev_rate_date_type,
                                    pbl.project_rev_rate_date,
                                    pbl.project_revenue,
                                    pbl.txn_currency_code,
                                    pbl.txn_raw_cost,
                                    pbl.txn_burdened_cost,
                                    pbl.txn_revenue,
                                    pbl.bucketing_period_code,
                                    pa_budget_lines_s.nextval,
                                    pbl.budget_version_id,
                                    pbl.txn_standard_cost_rate,
                                    DECODE(l_target_version_type,
                                         'REVENUE',pbl.txn_cost_rate_override,
                                          DECODE(l_targ_rate_based_flag_tbl(kk),
                                                 'N',1,
                                                 pbl.txn_cost_rate_override)),
                                    pbl.cost_ind_compiled_set_id,
                             --       pbl.  txn_burden_multiplier,
                             --       pbl.  txn_burden_multiplier_override,
                                    pbl.txn_standard_bill_rate,
                                    DECODE(l_target_version_type,
                                           'REVENUE',DECODE(l_targ_rate_based_flag_tbl(kk),
                                                            'N',1,
                                                            pbl.txn_bill_rate_override),
                                           pbl.txn_bill_rate_override),
                                    pbl.txn_markup_percent,
                                    pbl.txn_markup_percent_override,
                                    pbl.txn_discount_percentage,
                                    pbl.transfer_price_rate,
                                    pbl.burden_cost_rate,
                                    DECODE(l_target_version_type,
                                         'REVENUE',pbl.burden_cost_rate_override,
                                          DECODE(l_targ_rate_based_flag_tbl(kk),
                                                 'Y',pbl.burden_cost_rate_override,
                                                  DECODE(nvl(pbl.txn_raw_cost,0),
                                                         0,null,
                                                         pbl.txn_burdened_cost/pbl.txn_raw_cost))),
                                    pbl.pc_cur_conv_rejection_code,
                                    pbl.pfc_cur_conv_rejection_code
                         FROM(SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id), pras.resource_list_member_id) resource_assignment_id,
                                   pbls.start_date start_date,
                                   sysdate last_update_date,
                                   fnd_global.user_id last_updated_by,
                                   sysdate creation_date,
                                   fnd_global.user_id created_by,
                                   fnd_global.login_id last_update_login,
                                   pbls.end_date end_date,
                                   pbls.period_name period_name,
                                   decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                      decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)) quantity,
                                   sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)) raw_cost,
                                   sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)) burdened_cost,
                                   sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor revenue,
                                   decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null) change_reason_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.description),null) description,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null) attribute_category,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null) attribute1,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null) attribute2,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null) attribute3,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null) attribute4,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null) attribute5,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null) attribute6,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null) attribute7,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null) attribute8,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null) attribute9,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null) attribute10,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null) attribute11,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null) attribute12,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null) attribute13,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null) attribute14,
                                   decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null) attribute15,
                                   'I' raw_cost_source     ,
                                   'I' burdened_cost_source,
                                   'I' quantity_source     ,
                                   'I' revenue_source      ,
                                   decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null) pm_product_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null) pm_budget_line_reference,
                                   decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null) cost_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null) revenue_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null) burden_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null) other_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null) code_combination_id,
                                   decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null) ccid_gen_status_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null) ccid_gen_rej_message,
                                   decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null) request_id,
                                   decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null) borrowed_revenue,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null) tp_revenue_in,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null) tp_revenue_out,
                                   decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null) revenue_adj,
                                   decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null) lent_resource_cost,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null) tp_cost_in,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null)  tp_cost_out,
                                   decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null) cost_adj,
                                   decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null) unassigned_time_cost,
                                   decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null) utilization_percent,
                                   decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null) utilization_hours,
                                   decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null) utilization_adj,
                                   decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null) capacity,
                                   decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null) head_count,
                                   decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null) head_count_adj,
                                   l_projfunc_currency_code projfunc_currency_code,
                                   DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_cost_rate_type,
                                   null projfunc_cost_exchange_rate, --Bug 3839273
                                   null projfunc_cost_rate_date_type,
                                   null projfunc_cost_rate_date,
                                   Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_rev_rate_type,
                                   null projfunc_rev_exchange_rate, --Bug 3839273
                                   null projfunc_rev_rate_date_type,
                                   null projfunc_rev_rate_date,
                                   l_project_currency_code project_currency_code,
                                   DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null) project_cost_rate_type,
                                   null project_cost_exchange_rate, --Bug 3839273
                                   null project_cost_rate_date_type,
                                   null project_cost_rate_date,
                                   sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)) project_raw_cost,
                                   sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)) project_burdened_cost,
                                   Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null) project_rev_rate_type,
                                   null project_rev_exchange_rate, --Bug 3839273
                                   null project_rev_rate_date_type,
                                   null project_rev_rate_date,
                                   sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor project_revenue,
                                   DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)) txn_currency_code,


                                   --Bug 4224757.. Code changes for bug#4224757 starts here
                                   SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0)))))
                                   txn_raw_cost,
                                   SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                                   nvl(pbls.project_burdened_cost,0))))) txn_burdened_cost,
                                   SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
                                   DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                                   nvl(pbls.project_revenue,0)))))*l_partial_factor txn_revenue,
                                   --Bug 4224757.. Code changes for bug#4224757 ends here

                                   decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null) bucketing_period_code,
                                   p_budget_version_id budget_version_id,
                                   decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null) txn_standard_cost_rate,

                                   --Bug 4224757. Code changes for bug#4224757 starts here
                                   decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                                   decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                                  nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
                                   decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                        decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))     txn_cost_rate_override,
                                   --Bug 4224757. Code changes for bug#4224757 ends here



                                   decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null) cost_ind_compiled_set_id,
                            --         decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),

                                   decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null) txn_standard_bill_rate,

                                   --Bug 4224757. Code changes for bug#4224757 starts here
                                   decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
                                          decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
                                          'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
                                   decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                        decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_bill_rate_override,
                                   --Bug 4224757. Code changes for bug#4224757 ends here

                                   decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null) txn_markup_percent,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null) txn_markup_percent_override,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null) txn_discount_percentage,
                                   decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null) transfer_price_rate,
                                   decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null) burden_cost_rate,

                                   --Bug 4224757. Code changes for bug#4224757 starts here
                                   decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                                   decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag,
                                  'Y', nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
                                   decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                        decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) burden_cost_rate_override,
                                   --Bug 4224757. Code changes for bug#4224757 ends here


                                   decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null) pc_cur_conv_rejection_code,
                                   decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null) pfc_cur_conv_rejection_code
                              from   pa_budget_lines pbls,
                                   pa_resource_assignments pras
                              where  l_ra_dml_code_tbl(kk)='INSERT'
                              and    pras.budget_version_id = l_src_ver_id_tbl(j)
                              and    pras.resource_assignment_id = pbls.resource_assignment_id
                              and    get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id), pras.resource_list_member_id)=L_targ_ra_id_tbl(kk)
                                 --IPM Arch Enhancement Bug 4865563
                            /*and    pbls.cost_rejection_code IS NULL
                              and    pbls.revenue_rejection_code IS NULL
                              and    pbls.burden_rejection_code IS NULL
                              and    pbls.other_rejection_code IS NULL
                              and    pbls.pc_cur_conv_rejection_code IS NULL
                              and    pbls.pfc_cur_conv_rejection_code IS NULL*/
                              and    pbls.start_date >= nvl(l_etc_start_date,pbls.start_date)
                              GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pras.task_id),pras.resource_list_member_id) ,
                                     DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
                                     ,pbls.start_date,pbls.end_date,pbls.period_name)pbl;
Line: 7749

                                    pa_debug.g_err_stage:= 'SRC tp =targ TP. same RLS.Done with bulk insert BLs';
Line: 7756

                          pa_debug.g_err_stage:= 'About to bulk insert Budget lines with different RLs and  TP not N and src Tp= targ TP';
Line: 7763

                      INSERT INTO PA_BUDGET_LINES(
                               RESOURCE_ASSIGNMENT_ID,
                               START_DATE,
                               LAST_UPDATE_DATE,
                               LAST_UPDATED_BY,
                               CREATION_DATE,
                               CREATED_BY,
                               LAST_UPDATE_LOGIN,
                               END_DATE,
                               PERIOD_NAME,
                               QUANTITY,
                               RAW_COST,
                               BURDENED_COST,
                               REVENUE,
                               CHANGE_REASON_CODE,
                               DESCRIPTION,
                               ATTRIBUTE_CATEGORY,
                               ATTRIBUTE1,
                               ATTRIBUTE2,
                               ATTRIBUTE3,
                               ATTRIBUTE4,
                               ATTRIBUTE5,
                               ATTRIBUTE6,
                               ATTRIBUTE7,
                               ATTRIBUTE8,
                               ATTRIBUTE9,
                               ATTRIBUTE10,
                               ATTRIBUTE11,
                               ATTRIBUTE12,
                               ATTRIBUTE13,
                               ATTRIBUTE14,
                               ATTRIBUTE15,
                               RAW_COST_SOURCE,
                               BURDENED_COST_SOURCE,
                               QUANTITY_SOURCE,
                               REVENUE_SOURCE,
                               PM_PRODUCT_CODE,
                               PM_BUDGET_LINE_REFERENCE,
                               COST_REJECTION_CODE,
                               REVENUE_REJECTION_CODE,
                               BURDEN_REJECTION_CODE,
                               OTHER_REJECTION_CODE,
                               CODE_COMBINATION_ID,
                               CCID_GEN_STATUS_CODE,
                               CCID_GEN_REJ_MESSAGE,
                               REQUEST_ID,
                               BORROWED_REVENUE,
                               TP_REVENUE_IN,
                               TP_REVENUE_OUT,
                               REVENUE_ADJ,
                               LENT_RESOURCE_COST,
                               TP_COST_IN,
                               TP_COST_OUT,
                               COST_ADJ,
                               UNASSIGNED_TIME_COST,
                               UTILIZATION_PERCENT,
                               UTILIZATION_HOURS,
                               UTILIZATION_ADJ,
                               CAPACITY,
                               HEAD_COUNT,
                               HEAD_COUNT_ADJ,
                               PROJFUNC_CURRENCY_CODE,
                               PROJFUNC_COST_RATE_TYPE,
                               PROJFUNC_COST_EXCHANGE_RATE,
                               PROJFUNC_COST_RATE_DATE_TYPE,
                               PROJFUNC_COST_RATE_DATE,
                               PROJFUNC_REV_RATE_TYPE,
                               PROJFUNC_REV_EXCHANGE_RATE,
                               PROJFUNC_REV_RATE_DATE_TYPE,
                               PROJFUNC_REV_RATE_DATE,
                               PROJECT_CURRENCY_CODE,
                               PROJECT_COST_RATE_TYPE,
                               PROJECT_COST_EXCHANGE_RATE,
                               PROJECT_COST_RATE_DATE_TYPE,
                               PROJECT_COST_RATE_DATE,
                               PROJECT_RAW_COST,
                               PROJECT_BURDENED_COST,
                               PROJECT_REV_RATE_TYPE,
                               PROJECT_REV_EXCHANGE_RATE,
                               PROJECT_REV_RATE_DATE_TYPE,
                               PROJECT_REV_RATE_DATE,
                               PROJECT_REVENUE,
                               TXN_CURRENCY_CODE,
                               TXN_RAW_COST,
                               TXN_BURDENED_COST,
                               TXN_REVENUE,
                               BUCKETING_PERIOD_CODE,
                               BUDGET_LINE_ID,
                               BUDGET_VERSION_ID,
                               TXN_STANDARD_COST_RATE,
                               TXN_COST_RATE_OVERRIDE,
                               COST_IND_COMPILED_SET_ID,
                         --        TXN_BURDEN_MULTIPLIER,
                         --        TXN_BURDEN_MULTIPLIER_OVERRIDE,
                               TXN_STANDARD_BILL_RATE,
                               TXN_BILL_RATE_OVERRIDE,
                               TXN_MARKUP_PERCENT,
                               TXN_MARKUP_PERCENT_OVERRIDE,
                               TXN_DISCOUNT_PERCENTAGE,
                               TRANSFER_PRICE_RATE,
                               BURDEN_COST_RATE,
                               BURDEN_COST_RATE_OVERRIDE,
                               PC_CUR_CONV_REJECTION_CODE,
                               PFC_CUR_CONV_REJECTION_CODE
                               )
                         SELECT    pbl.resource_assignment_id,
                               pbl.start_date,
                               pbl.last_update_date,
                               pbl.last_updated_by,
                               pbl.creation_date,
                               pbl.created_by,
                               pbl.last_update_login,
                               pbl.end_date,
                               pbl.period_name,
                               DECODE(l_targ_rate_based_flag_tbl(kk),
                                      'N',DECODE(l_target_version_type,
                                                 'REVENUE',pbl.txn_revenue
                                                          ,pbl.txn_raw_cost),
                                       pbl.quantity),
                               pbl.raw_cost,
                               pbl.burdened_cost,
                               pbl.revenue,
                               pbl.change_reason_code,
                               pbl.description,
                               pbl.attribute_category,
                               pbl.attribute1,
                               pbl.attribute2,
                               pbl.attribute3,
                               pbl.attribute4,
                               pbl.attribute5,
                               pbl.attribute6,
                               pbl.attribute7,
                               pbl.attribute8,
                               pbl.attribute9,
                               pbl.attribute10,
                               pbl.attribute11,
                               pbl.attribute12,
                               pbl.attribute13,
                               pbl.attribute14,
                               pbl.attribute15,
                               pbl.raw_cost_source,
                               pbl.burdened_cost_source,
                               pbl.quantity_source,
                               pbl.revenue_source,
                               pbl.pm_product_code,
                               pbl.pm_budget_line_reference,
                               pbl.cost_rejection_code,
                               pbl.revenue_rejection_code,
                               pbl.burden_rejection_code,
                               pbl.other_rejection_code,
                               pbl.code_combination_id,
                               pbl.ccid_gen_status_code,
                               pbl.ccid_gen_rej_message,
                               pbl.request_id,
                               pbl.borrowed_revenue,
                               pbl.tp_revenue_in,
                               pbl.tp_revenue_out,
                               pbl.revenue_adj,
                               pbl.lent_resource_cost,
                               pbl.tp_cost_in,
                               pbl.tp_cost_out,
                               pbl.cost_adj,
                               pbl.unassigned_time_cost,
                               pbl.utilization_percent,
                               pbl.utilization_hours,
                               pbl.utilization_adj,
                               pbl.capacity,
                               pbl.head_count,
                               pbl.head_count_adj,
                               pbl.projfunc_currency_code,
                               pbl.projfunc_cost_rate_type,
                               DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
                                                 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.raw_cost,0),
                                                 'B',nvl(pbl.burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
                                                 'B', pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
                               pbl.projfunc_cost_rate_date_type,
                               pbl.projfunc_cost_rate_date,
                               pbl.projfunc_rev_rate_type,
                               Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y',  Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
                               pbl.projfunc_rev_rate_date_type,
                               pbl.projfunc_rev_rate_date,
                               pbl.project_currency_code,
                               pbl.project_cost_rate_type,
                               DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(pbl.txn_raw_cost,0),
                                                 'B', nvl(pbl.txn_burdened_cost,0)),0,0,(decode(l_report_cost_using,'R',nvl(pbl.project_raw_cost,0),
                                                 'B',nvl(pbl.project_burdened_cost,0)) / decode(l_report_cost_using,'R',pbl.txn_raw_cost,
                                                 'B',pbl.txn_burdened_cost))),Null),Null), --Bug 3839273
                               pbl.project_cost_rate_date_type,
                               pbl.project_cost_rate_date,
                               pbl.project_raw_cost,
                               pbl.project_burdened_cost,
                               pbl.project_rev_rate_type,
                               Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(pbl.txn_revenue,0),0,0,(nvl(pbl.project_revenue,0) /pbl.txn_revenue)),Null),Null), --Bug 3839273
                               pbl.project_rev_rate_date_type,
                               pbl.project_rev_rate_date,
                               pbl.project_revenue,
                               pbl.txn_currency_code,
                               pbl.txn_raw_cost,
                               pbl.txn_burdened_cost,
                               pbl.txn_revenue,
                               pbl.bucketing_period_code,
                               pa_budget_lines_s.nextval,
                               pbl.budget_version_id,
                               pbl.txn_standard_cost_rate,
                               DECODE(l_target_version_type,
                                      'REVENUE',pbl.txn_cost_rate_override,
                                      DECODE(l_targ_rate_based_flag_tbl(kk),
                                             'N',1,
                                             pbl.txn_cost_rate_override)),
                               pbl.cost_ind_compiled_set_id,
                         --      pbl.  txn_burden_multiplier,
                         --      pbl.  txn_burden_multiplier_override,
                               pbl.txn_standard_bill_rate,
                               DECODE(l_target_version_type,
                                      'REVENUE',DECODE(l_targ_rate_based_flag_tbl(kk),
                                                       'N',1,
                                                       pbl.txn_bill_rate_override),
                                      pbl.txn_bill_rate_override),
                               pbl.txn_markup_percent,
                               pbl.txn_markup_percent_override,
                               pbl.txn_discount_percentage,
                               pbl.transfer_price_rate,
                               pbl.burden_cost_rate,
                               DECODE(l_target_version_type,
                                      'REVENUE',pbl.burden_cost_rate_override,
                                       DECODE(l_targ_rate_based_flag_tbl(kk),
                                              'Y',pbl.burden_cost_rate_override,
                                              DECODE(nvl(pbl.txn_raw_cost,0),
                                                     0,null,
                                                     pbl.txn_burdened_cost/pbl.txn_raw_cost))),
                               pbl.pc_cur_conv_rejection_code,
                               pbl.pfc_cur_conv_rejection_code
                         FROM(SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,rlmap.task_id), rlmap.resource_list_member_id) resource_assignment_id,
                              pbls.start_date start_date,
                              sysdate last_update_date,
                              fnd_global.user_id last_updated_by,
                              sysdate creation_date,
                              fnd_global.user_id created_by,
                              fnd_global.login_id last_update_login,
                              pbls.end_date end_date,
                              pbls.period_name period_name,
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                   decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)) quantity,
                              sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)) raw_cost,
                              sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)) burdened_cost,
                              sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor revenue,
                              decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null) change_reason_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.description),null) description,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null) attribute_category,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null) attribute1,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null) attribute2,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null) attribute3,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null) attribute4,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null) attribute5,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null) attribute6,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null) attribute7,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null) attribute8,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null) attribute9,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null) attribute10,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null) attribute11,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null) attribute12,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null) attribute13,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null) attribute14,
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null) attribute15,
                              'I' raw_cost_source     ,
                              'I' burdened_cost_source,
                              'I' quantity_source     ,
                              'I' revenue_source      ,
                              decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null) pm_product_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null) pm_budget_line_reference,
                              decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null) cost_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null) revenue_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null) burden_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null) other_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null) code_combination_id,
                              decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null) ccid_gen_status_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null) ccid_gen_rej_message,
                              decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null) request_id,
                              decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null) borrowed_revenue,
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null) tp_revenue_in,
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null) tp_revenue_out,
                              decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null) revenue_adj,
                              decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null) lent_resource_cost,
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null) tp_cost_in,
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null) tp_cost_out,
                              decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null) cost_adj,
                              decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null) unassigned_time_cost,
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null) utilization_percent,
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null) utilization_hours,
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null) utilization_adj,
                              decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null) capacity,
                              decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null) head_count,
                              decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null) head_count_adj,
                              l_projfunc_currency_code projfunc_currency_code,
                              DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_cost_rate_type,
                              null projfunc_cost_exchange_rate, --Bug 3839273
                              null projfunc_cost_rate_date_type,
                              null projfunc_cost_rate_date,
                              Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null) projfunc_rev_rate_type,
                              null projfunc_rev_exchange_rate, --Bug 3839273
                              null projfunc_rev_rate_date_type,
                              null projfunc_rev_rate_date,
                              l_project_currency_code project_currency_code,
                              DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null) project_cost_rate_type,
                              null project_cost_exchange_rate, --Bug 3839273
                              null project_cost_rate_date_type,
                              null project_cost_rate_date,
                              sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost, null)) project_raw_cost,
                              sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost, null)) project_burdened_cost,
                              Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null) project_rev_rate_type,
                              null project_rev_exchange_rate, --Bug 3839273
                              null project_rev_rate_date_type ,
                              null project_rev_rate_date ,
                              sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor project_revenue,
                              DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)) txn_currency_code,


                              --Bug 4224757.. Code changes for bug#4224757 starts here
                              SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0)))))
                              txn_raw_cost,
                              SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                              nvl(pbls.project_burdened_cost,0))))) txn_burdened_cost,
                              SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                              nvl(pbls.project_revenue,0)))))*l_partial_factor txn_revenue,
                              --Bug 4224757.. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null) bucketing_period_code,
                              p_budget_version_id budget_version_id,
                              decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null) txn_standard_cost_rate,

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                              decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                               nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                              decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))     txn_cost_rate_override,
                              --Bug 4224757. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null) cost_ind_compiled_set_id,
                      --            decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),

                              decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null) txn_standard_bill_rate,

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
                                  decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
                                    'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                   decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) txn_bill_rate_override,
                              --Bug 4224757. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null) txn_markup_percent,
                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null) txn_markup_percent_override,
                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null) txn_discount_percentage,
                              decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null) transfer_price_rate,
                              decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null) burden_cost_rate,

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                              decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                                nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) burden_cost_rate_override,
                              --Bug 4224757. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null) pc_cur_conv_rejection_code,
                              decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)  pfc_cur_conv_rejection_code
                         from   pa_budget_lines pbls,
                              (SELECT pra.task_id task_id,
                                    tmp4.resource_list_member_id resource_list_member_id,
                                    tmp4.txn_source_id resource_assignment_id
                               FROM   pa_resource_assignments pra,
                                    pa_res_list_map_tmp4 tmp4
                               WHERE  tmp4.txn_source_id=pra.resource_assignment_id) rlmap
                         where  l_ra_dml_code_tbl(kk)='INSERT'
                         and    rlmap.resource_assignment_id = pbls.resource_assignment_id
                         and    get_mapped_ra_id(get_task_id(l_targ_plan_level_code,rlmap.task_id), rlmap.resource_list_member_id)=L_targ_ra_id_tbl(kk)
                         --IPM Arch Enhancement Bug 4865563
                       /*and    pbls.cost_rejection_code IS NULL
                         and    pbls.revenue_rejection_code IS NULL
                         and    pbls.burden_rejection_code IS NULL
                         and    pbls.other_rejection_code IS NULL
                         and    pbls.pc_cur_conv_rejection_code IS NULL
                         and    pbls.pfc_cur_conv_rejection_code IS NULL*/
                         and    pbls.start_date >= nvl(l_etc_start_date, pbls.start_date)
                         GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,rlmap.task_id),rlmap.resource_list_member_id) ,
                                DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
                                ,pbls.start_date,pbls.end_date,pbls.period_name)pbl;
Line: 8156

                          pa_debug.g_err_stage:= 'Done with bulk insert Budget lines with different RLs and  TP not N and src Tp= targ TP'||SQL%ROWCOUNT;
Line: 8167

                                pa_debug.g_err_stage:= 'About to bulk insert resource assignments';
Line: 8172

                             SELECT get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code),
                             decode(pblt.resource_assignment_id,null, 'INSERT',
                                                   decode(pblt.txn_currency_code, null,'INSERT','UPDATE')),
                             decode(pblt.resource_assignment_id,null, prat.planning_start_date,
                                                   decode(pblt.txn_currency_code, null,prat.planning_start_date,pblt.start_date)),
                             decode(pblt.resource_assignment_id,null, prat.planning_end_date,
                                                   decode(pblt.txn_currency_code, null,prat.planning_end_date,pblt.end_date)),
                             NULL,
                             decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)),
                             sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)),
                             sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)),
                             sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor,
                             decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.description),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null),

                             decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null),
                             l_projfunc_currency_code,
                             DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null),
                             Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null),
                             DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null),
                             sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)),
                             sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost, null)),
                             Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null),
                             sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor,
                             DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),


                             --Bug 4224757.. Code changes for bug#4224757 starts here
                             SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
                             DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))))) ,
                             SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
                             DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                             nvl(pbls.project_burdened_cost,0))))) ,
                             SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
                             DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                             nvl(pbls.project_revenue,0)))))*l_partial_factor ,
                             --Bug 4224757.. Code changes for bug#4224757 ends here

                             decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null),

                             --Bug 4224757. Code changes for bug#4224757 starts here
                             decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                             decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                              nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
                             decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                             decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))   ,
                             --Bug 4224757. Code changes for bug#4224757 ends here

                             decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null),
                        --     decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),

                             decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null),

                             --Bug 4224757. Code changes for bug#4224757 starts here
                             decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
                                  decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
                                    'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
                             decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                  decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
                             --Bug 4224757. Code changes for bug#4224757 ends here

                             decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null),


                             --Bug 4224757. Code changes for bug#4224757 starts here
                             decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                             decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                             nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
                             decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                           decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
                             --Bug 4224757. Code changes for bug#4224757 ends here

                             decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null),
                             decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)
                        BULK COLLECT INTO
                         l_bl_RESOURCE_ASIGNMENT_ID_tbl,
                         l_upd_ra_bl_dml_code_tbl,
                         l_bl_START_DATE_tbl,
                         l_bl_END_DATE_tbl,
                         l_bl_PERIOD_NAME_tbl,
                         l_bl_QUANTITY_tbl,
                         l_bl_RAW_COST_tbl,
                         l_bl_BURDENED_COST_tbl,
                         l_bl_REVENUE_tbl,
                         l_bl_CHANGE_REASON_CODE_tbl,
                         l_bl_DESCRIPTION_tbl,
                         l_bl_ATTRIBUTE_CATEGORY_tbl,
                         l_bl_ATTRIBUTE1_tbl,
                         l_bl_ATTRIBUTE2_tbl,
                         l_bl_ATTRIBUTE3_tbl,
                         l_bl_ATTRIBUTE4_tbl,
                         l_bl_ATTRIBUTE5_tbl,
                         l_bl_ATTRIBUTE6_tbl,
                         l_bl_ATTRIBUTE7_tbl,
                         l_bl_ATTRIBUTE8_tbl,
                         l_bl_ATTRIBUTE9_tbl,
                         l_bl_ATTRIBUTE10_tbl,
                         l_bl_ATTRIBUTE11_tbl,
                         l_bl_ATTRIBUTE12_tbl,
                         l_bl_ATTRIBUTE13_tbl,
                         l_bl_ATTRIBUTE14_tbl,
                         l_bl_ATTRIBUTE15_tbl,
                         l_bl_PM_PRODUCT_CODE_tbl,
                         l_bl_PM_BUDGET_LINE_REF_tbl,
                         l_bl_COST_REJECTION_CODE_tbl,
                         l_bl_REVENUE_REJ_CODE_tbl,
                         l_bl_BURDEN_REJECTION_CODE_tbl,
                         l_bl_OTHER_REJECTION_CODE_tbl,
                         l_bl_CODE_COMBINATION_ID_tbl,
                         l_bl_CCID_GEN_STATUS_CODE_tbl,
                         l_bl_CCID_GEN_REJ_MESSAGE_tbl,
                         l_bl_REQUEST_ID_tbl,
                         l_bl_BORROWED_REVENUE_tbl,
                         l_bl_TP_REVENUE_IN_tbl,
                         l_bl_TP_REVENUE_OUT_tbl,
                         l_bl_REVENUE_ADJ_tbl,
                         l_bl_LENT_RESOURCE_COST_tbl,
                         l_bl_TP_COST_IN_tbl,
                         l_bl_TP_COST_OUT_tbl,
                         l_bl_COST_ADJ_tbl,
                         l_bl_UNASSIGNED_TIME_COST_tbl,
                         l_bl_UTILIZATION_PERCENT_tbl,
                         l_bl_UTILIZATION_HOURS_tbl,
                         l_bl_UTILIZATION_ADJ_tbl,
                         l_bl_CAPACITY_tbl,
                         l_bl_HEAD_COUNT_tbl,
                         l_bl_HEAD_COUNT_ADJ_tbl,
                         l_bl_PROJFUNC_CUR_CODE_tbl,
                         l_bl_PROJFUNC_COST_RAT_TYP_tbl,
                         l_bl_PJFN_COST_RAT_DAT_TYP_tbl,
                         l_bl_PROJFUNC_COST_RAT_DAT_tbl,
                         l_bl_PROJFUNC_REV_RATE_TYP_tbl,
                         l_bl_PJFN_REV_RAT_DAT_TYPE_tbl,
                         l_bl_PROJFUNC_REV_RAT_DATE_tbl,
                         l_bl_PROJECT_COST_RAT_TYPE_tbl,
                         l_bl_PROJ_COST_RAT_DAT_TYP_tbl,
                         l_bl_PROJ_COST_RATE_DATE_tbl,
                         l_bl_PROJECT_RAW_COST_tbl,
                         l_bl_PROJECT_BURDENED_COST_tbl,
                         l_bl_PROJECT_REV_RATE_TYPE_tbl,
                         l_bl_PRJ_REV_RAT_DATE_TYPE_tbl,
                         l_bl_PROJECT_REV_RATE_DATE,
                         l_bl_PROJECT_REVENUE_tbl,
                         l_bl_TXN_CURRENCY_CODE_tbl,
                         l_bl_TXN_RAW_COST_tbl,
                         l_bl_TXN_BURDENED_COST_tbl,
                         l_bl_TXN_REVENUE_tbl,
                         l_bl_BUCKETING_PERIOD_CODE_tbl,
                         l_bl_TXN_STD_COST_RATE_tbl,
                         l_bl_TXN_COST_RATE_OVERIDE_tbl,
                         l_bl_COST_IND_CMPLD_SET_ID_tbl,
                   --        l_bl_TXN_BURDEN_MULTIPLIER_tbl,
                   --        l_bl_TXN_BRD_MLTIPLI_OVRID_tbl,
                         l_bl_TXN_STD_BILL_RATE_tbl,
                         l_bl_TXN_BILL_RATE_OVERRID_tbl,
                         l_bl_TXN_MARKUP_PERCENT_tbl,
                         l_bl_TXN_MRKUP_PER_OVERIDE_tbl,
                         l_bl_TXN_DISC_PERCENTAGE_tbl,
                         l_bl_TRANSFER_PRICE_RATE_tbl,
                         l_bl_BURDEN_COST_RATE_tbl,
                         l_bl_BURDEN_COST_RAT_OVRID_tbl,
                         l_bl_PC_CUR_CONV_REJ_CODE_tbl,
                         l_bl_PFC_CUR_CONV_REJ_CODE_tbl
                        from   pa_budget_lines pbls,
                               pa_budget_lines pblt,
                               pa_resource_assignments prat
                        where  get_mapped_dml_code(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)='UPDATE'
                        and    pbls.budget_version_id = l_src_ver_id_tbl(j)
                        and    pblt.budget_version_id(+) = p_budget_version_id
                        and    pblt.resource_assignment_id(+)=get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)
                        AND    pblt.txn_currency_code(+)=DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,
                                                      DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
                        and    prat.resource_assignment_id = get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)
                        --IPM Arch Enhancement Bug 4865563
                      /*and    pbls.cost_rejection_code IS NULL
                        and    pbls.revenue_rejection_code IS NULL
                        and    pbls.burden_rejection_code IS NULL
                        and    pbls.other_rejection_code IS NULL
                        and    pbls.pc_cur_conv_rejection_code IS NULL
                        and    pbls.pfc_cur_conv_rejection_code IS NULL*/
                        GROUP BY get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code),
                        DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
                        pblt.resource_assignment_id,
                        pblt.txn_currency_code,
                        pblt.start_date,
                        pblt.end_date,
                        prat.planning_start_date,
                        prat.planning_end_date;
Line: 8419

                                    pa_debug.g_err_stage:= 'About to bulk select for ins/upd the budget lins with targ NTP and Diff RLS';
Line: 8424

                              SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id),
                              decode(pblt.resource_assignment_id,null, 'INSERT',
                                                         decode(pblt.txn_currency_code, null,'INSERT','UPDATE')),
                              decode(pblt.resource_assignment_id,null, prat.planning_start_date,
                                                         decode(pblt.txn_currency_code, null,prat.planning_start_date,pblt.start_date)),
                              decode(pblt.resource_assignment_id,null, prat.planning_end_date,
                                                         decode(pblt.txn_currency_code, null,prat.planning_end_date,pblt.end_date)),
                              NULL,
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                   decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)),
                              sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)),
                              sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)),
                              sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor,
                              decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.description),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null),
                              l_projfunc_currency_code,
                              DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null),
                              Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null),
                              DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null),
                              sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost, null)),
                              sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)),
                              Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null),
                              sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor,
                              DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),


                              --Bug 4224757.. Code changes for bug#4224757 starts here
                              SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))))),
                              SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                              nvl(pbls.project_burdened_cost,0))))) ,
                              SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
                              DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                              nvl(pbls.project_revenue,0)))))*l_partial_factor ,
                              --Bug 4224757.. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null),

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                              decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                               nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))   ,
                              --Bug 4224757. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null),
                           --     decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),

                              decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null),

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
                                 decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
                                   'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                   decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
                                 --Bug 4224757. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null),

                              --Bug 4224757. Code changes for bug#4224757 starts here
                              decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                              decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                               nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
                              decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                         decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
                              --Bug 4224757. Code changes for bug#4224757 ends here

                              decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null),
                              decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)
                         BULK COLLECT INTO
                               l_bl_RESOURCE_ASIGNMENT_ID_tbl,
                               l_upd_ra_bl_dml_code_tbl,
                               l_bl_START_DATE_tbl,
                               l_bl_END_DATE_tbl,
                               l_bl_PERIOD_NAME_tbl,
                               l_bl_QUANTITY_tbl,
                               l_bl_RAW_COST_tbl,
                               l_bl_BURDENED_COST_tbl,
                               l_bl_REVENUE_tbl,
                               l_bl_CHANGE_REASON_CODE_tbl,
                               l_bl_DESCRIPTION_tbl,
                               l_bl_ATTRIBUTE_CATEGORY_tbl,
                               l_bl_ATTRIBUTE1_tbl,
                               l_bl_ATTRIBUTE2_tbl,
                               l_bl_ATTRIBUTE3_tbl,
                               l_bl_ATTRIBUTE4_tbl,
                               l_bl_ATTRIBUTE5_tbl,
                               l_bl_ATTRIBUTE6_tbl,
                               l_bl_ATTRIBUTE7_tbl,
                               l_bl_ATTRIBUTE8_tbl,
                               l_bl_ATTRIBUTE9_tbl,
                               l_bl_ATTRIBUTE10_tbl,
                               l_bl_ATTRIBUTE11_tbl,
                               l_bl_ATTRIBUTE12_tbl,
                               l_bl_ATTRIBUTE13_tbl,
                               l_bl_ATTRIBUTE14_tbl,
                               l_bl_ATTRIBUTE15_tbl,
                               l_bl_PM_PRODUCT_CODE_tbl,
                               l_bl_PM_BUDGET_LINE_REF_tbl,
                               l_bl_COST_REJECTION_CODE_tbl,
                               l_bl_REVENUE_REJ_CODE_tbl,
                               l_bl_BURDEN_REJECTION_CODE_tbl,
                               l_bl_OTHER_REJECTION_CODE_tbl,
                               l_bl_CODE_COMBINATION_ID_tbl,
                               l_bl_CCID_GEN_STATUS_CODE_tbl,
                               l_bl_CCID_GEN_REJ_MESSAGE_tbl,
                               l_bl_REQUEST_ID_tbl,
                               l_bl_BORROWED_REVENUE_tbl,
                               l_bl_TP_REVENUE_IN_tbl,
                               l_bl_TP_REVENUE_OUT_tbl,
                               l_bl_REVENUE_ADJ_tbl,
                               l_bl_LENT_RESOURCE_COST_tbl,
                               l_bl_TP_COST_IN_tbl,
                               l_bl_TP_COST_OUT_tbl,
                               l_bl_COST_ADJ_tbl,
                               l_bl_UNASSIGNED_TIME_COST_tbl,
                               l_bl_UTILIZATION_PERCENT_tbl,
                               l_bl_UTILIZATION_HOURS_tbl,
                               l_bl_UTILIZATION_ADJ_tbl,
                               l_bl_CAPACITY_tbl,
                               l_bl_HEAD_COUNT_tbl,
                               l_bl_HEAD_COUNT_ADJ_tbl,
                               l_bl_PROJFUNC_CUR_CODE_tbl,
                               l_bl_PROJFUNC_COST_RAT_TYP_tbl,
                               l_bl_PJFN_COST_RAT_DAT_TYP_tbl,
                               l_bl_PROJFUNC_COST_RAT_DAT_tbl,
                               l_bl_PROJFUNC_REV_RATE_TYP_tbl,
                               l_bl_PJFN_REV_RAT_DAT_TYPE_tbl,
                               l_bl_PROJFUNC_REV_RAT_DATE_tbl,
                               l_bl_PROJECT_COST_RAT_TYPE_tbl,
                               l_bl_PROJ_COST_RAT_DAT_TYP_tbl,
                               l_bl_PROJ_COST_RATE_DATE_tbl,
                               l_bl_PROJECT_RAW_COST_tbl,
                               l_bl_PROJECT_BURDENED_COST_tbl,
                               l_bl_PROJECT_REV_RATE_TYPE_tbl,
                               l_bl_PRJ_REV_RAT_DATE_TYPE_tbl,
                               l_bl_PROJECT_REV_RATE_DATE,
                               l_bl_PROJECT_REVENUE_tbl,
                               l_bl_TXN_CURRENCY_CODE_tbl,
                               l_bl_TXN_RAW_COST_tbl,
                               l_bl_TXN_BURDENED_COST_tbl,
                               l_bl_TXN_REVENUE_tbl,
                               l_bl_BUCKETING_PERIOD_CODE_tbl,
                               l_bl_TXN_STD_COST_RATE_tbl,
                               l_bl_TXN_COST_RATE_OVERIDE_tbl,
                               l_bl_COST_IND_CMPLD_SET_ID_tbl,
                           --      l_bl_TXN_BURDEN_MULTIPLIER_tbl,
                           --      l_bl_TXN_BRD_MLTIPLI_OVRID_tbl,
                               l_bl_TXN_STD_BILL_RATE_tbl,
                               l_bl_TXN_BILL_RATE_OVERRID_tbl,
                               l_bl_TXN_MARKUP_PERCENT_tbl,
                               l_bl_TXN_MRKUP_PER_OVERIDE_tbl,
                               l_bl_TXN_DISC_PERCENTAGE_tbl,
                               l_bl_TRANSFER_PRICE_RATE_tbl,
                               l_bl_BURDEN_COST_RATE_tbl,
                               l_bl_BURDEN_COST_RAT_OVRID_tbl,
                               l_bl_PC_CUR_CONV_REJ_CODE_tbl,
                               l_bl_PFC_CUR_CONV_REJ_CODE_tbl
                         from   pa_budget_lines pblt,
                                pa_resource_assignments prat,
                           (SELECT  pbls.resource_assignment_id
                                 ,pbls.start_date
                                 ,pbls.last_update_date
                                 ,pbls.last_updated_by
                                 ,pbls.creation_date
                                 ,pbls.created_by
                                 ,pbls.last_update_login
                                 ,pbls.end_date
                                 ,pbls.period_name
                                 ,pbls.quantity
                                 ,pbls.raw_cost
                                 ,pbls.burdened_cost
                                 ,pbls.revenue
                                 ,pbls.change_reason_code
                                 ,pbls.description
                                 ,pbls.attribute_category
                                 ,pbls.attribute1
                                 ,pbls.attribute2
                                 ,pbls.attribute3
                                 ,pbls.attribute4
                                 ,pbls.attribute5
                                 ,pbls.attribute6
                                 ,pbls.attribute7
                                 ,pbls.attribute8
                                 ,pbls.attribute9
                                 ,pbls.attribute10
                                 ,pbls.attribute11
                                 ,pbls.attribute12
                                 ,pbls.attribute13
                                 ,pbls.attribute14
                                 ,pbls.attribute15
                                 ,pbls.raw_cost_source
                                 ,pbls.burdened_cost_source
                                 ,pbls.quantity_source
                                 ,pbls.revenue_source
                                 ,pbls.pm_product_code
                                 ,pbls.pm_budget_line_reference
                                 ,pbls.cost_rejection_code
                                 ,pbls.revenue_rejection_code
                                 ,pbls.burden_rejection_code
                                 ,pbls.other_rejection_code
                                 ,pbls.code_combination_id
                                 ,pbls.ccid_gen_status_code
                                 ,pbls.ccid_gen_rej_message
                                 ,pbls.request_id
                                 ,pbls.borrowed_revenue
                                 ,pbls.tp_revenue_in
                                 ,pbls.tp_revenue_out
                                 ,pbls.revenue_adj
                                 ,pbls.lent_resource_cost
                                 ,pbls.tp_cost_in
                                 ,pbls.tp_cost_out
                                 ,pbls.cost_adj
                                 ,pbls.unassigned_time_cost
                                 ,pbls.utilization_percent
                                 ,pbls.utilization_hours
                                 ,pbls.utilization_adj
                                 ,pbls.capacity
                                 ,pbls.head_count
                                 ,pbls.head_count_adj
                                 ,pbls.projfunc_currency_code
                                 ,pbls.projfunc_cost_rate_type
                                 ,pbls.projfunc_cost_exchange_rate
                                 ,pbls.projfunc_cost_rate_date_type
                                 ,pbls.projfunc_cost_rate_date
                                 ,pbls.projfunc_rev_rate_type
                                 ,pbls.projfunc_rev_exchange_rate
                                 ,pbls.projfunc_rev_rate_date_type
                                 ,pbls.projfunc_rev_rate_date
                                 ,pbls.project_currency_code
                                 ,pbls.project_cost_rate_type
                                 ,pbls.project_cost_exchange_rate
                                 ,pbls.project_cost_rate_date_type
                                 ,pbls.project_cost_rate_date
                                 ,pbls.project_raw_cost
                                 ,pbls.project_burdened_cost
                                 ,pbls.project_rev_rate_type
                                 ,pbls.project_rev_exchange_rate
                                 ,pbls.project_rev_rate_date_type
                                 ,pbls.project_rev_rate_date
                                 ,pbls.project_revenue
                                 ,pbls.txn_currency_code
                                 ,pbls.txn_raw_cost
                                 ,pbls.txn_burdened_cost
                                 ,pbls.txn_revenue
                                 ,pbls.bucketing_period_code
                                 ,pbls.budget_line_id
                                 ,pbls.budget_version_id
                                 ,pbls.txn_standard_cost_rate
                                 ,pbls.txn_cost_rate_override
                                 ,pbls.cost_ind_compiled_set_id
                                 ,pbls.txn_standard_bill_rate
                                 ,pbls.txn_bill_rate_override
                                 ,pbls.txn_markup_percent
                                 ,pbls.txn_markup_percent_override
                                 ,pbls.txn_discount_percentage
                                 ,pbls.transfer_price_rate
                                 ,pbls.burden_cost_rate
                                 ,pbls.burden_cost_rate_override
                                 ,pbls.pc_cur_conv_rejection_code
                                 ,pbls.pfc_cur_conv_rejection_code
                                 ,pras.resource_assignment_id
                                 ,pras.task_id
                                 ,tmp4.resource_list_member_id
                             FROM   pa_resource_assignments pras,
                                  pa_res_list_map_tmp4 tmp4,
                                  pa_budget_lines pbls
                             WHERE  tmp4.txn_source_id=pras.resource_assignment_id
                             AND    pbls.resource_assignment_id=pras.resource_assignment_id) pbls
                         where  get_mapped_dml_code(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id)='UPDATE'
                         and    pblt.budget_version_id(+) = p_budget_version_id
                         and    pblt.resource_assignment_id(+)=get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id)
                         AND    pblt.txn_currency_code(+)=DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,
                                                       DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
                         and    prat.resource_assignment_id=get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id)
                         --IPM Arch Enhancement Bug 4865563
                       /*and    pbls.cost_rejection_code IS NULL
                         and    pbls.revenue_rejection_code IS NULL
                         and    pbls.burden_rejection_code IS NULL
                         and    pbls.other_rejection_code IS NULL
                         and    pbls.pc_cur_conv_rejection_code IS NULL
                         and    pbls.pfc_cur_conv_rejection_code IS NULL*/
                         GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id), DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code),
                                pblt.resource_assignment_id,pblt.txn_currency_code,pblt.start_date,prat.planning_start_date, prat.planning_end_date,pblt.end_date ;
Line: 8767

                              pa_debug.g_err_stage:= 'Done with bulk select for ins/upd the budget lins with targ NTP and Diff RLS';
Line: 8779

                         pa_debug.g_err_stage:='About to select bls for PA/GL TP and same resource list';
Line: 8785

                     SELECT get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code),
                         decode(pblt.resource_assignment_id,null, 'INSERT',
                                                   decode(pblt.txn_currency_code, null,'INSERT',
                                                      decode(pblt.start_date,null,'INSERT','UPDATE'))),
                         pbls.start_date,
                         pbls.end_date,
                         pbls.period_name,
                         decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                            decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)),
                         sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost,null)),
                         sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost, null)),
                         sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue, null))*l_partial_factor,
                         decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.description),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null),
                         l_projfunc_currency_code,
                         DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null),
                         Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null),
                         DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null),
                         sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)),
                         sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost, null)),
                         Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null),
                         sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor,
                         DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),
                         --Bug 4247568. Code changes for bug 4247568  starts here. If src multi curr flag and targ multi curr flag are  -- diff then reutrn project raw cost, project burdened cost  and project  revenue.
                         SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))))),
                         SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
                         DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))))),
                         SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
                         DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor,
                         --Bug 4247568. Code changes for bug 4247568  ends here.
                         decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null),

                         --Bug 4224757. Code changes for bug#4224757 starts here
                         decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                         decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                        nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
                         decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                         decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))   ,
                         --Bug 4224757. Code changes for bug#4224757 ends here

                         decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null),
                    --       decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),

                         decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null),

                         --Bug 4224757. Code changes for bug#4224757 starts here
                         decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
                               decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
                                   'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
                         decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                              decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
                         --Bug 4224757. Code changes for bug#4224757 ends here


                         decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null),

                         --Bug 4224757. Code changes for bug#4224757 starts here
                         decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                         decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                          nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
                         decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                      decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
                         --Bug 4224757. Code changes for bug#4224757 ends here

                         decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null),
                         decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)
                        BULK COLLECT INTO
                         l_bl_RESOURCE_ASIGNMENT_ID_tbl,
                         l_upd_ra_bl_dml_code_tbl,
                         l_bl_START_DATE_tbl,
                         l_bl_END_DATE_tbl,
                         l_bl_PERIOD_NAME_tbl,
                         l_bl_QUANTITY_tbl,
                         l_bl_RAW_COST_tbl,
                         l_bl_BURDENED_COST_tbl,
                         l_bl_REVENUE_tbl,
                         l_bl_CHANGE_REASON_CODE_tbl,
                         l_bl_DESCRIPTION_tbl,
                         l_bl_ATTRIBUTE_CATEGORY_tbl,
                         l_bl_ATTRIBUTE1_tbl,
                         l_bl_ATTRIBUTE2_tbl,
                         l_bl_ATTRIBUTE3_tbl,
                         l_bl_ATTRIBUTE4_tbl,
                         l_bl_ATTRIBUTE5_tbl,
                         l_bl_ATTRIBUTE6_tbl,
                         l_bl_ATTRIBUTE7_tbl,
                         l_bl_ATTRIBUTE8_tbl,
                         l_bl_ATTRIBUTE9_tbl,
                         l_bl_ATTRIBUTE10_tbl,
                         l_bl_ATTRIBUTE11_tbl,
                         l_bl_ATTRIBUTE12_tbl,
                         l_bl_ATTRIBUTE13_tbl,
                         l_bl_ATTRIBUTE14_tbl,
                         l_bl_ATTRIBUTE15_tbl,
                         l_bl_PM_PRODUCT_CODE_tbl,
                         l_bl_PM_BUDGET_LINE_REF_tbl,
                         l_bl_COST_REJECTION_CODE_tbl,
                         l_bl_REVENUE_REJ_CODE_tbl,
                         l_bl_BURDEN_REJECTION_CODE_tbl,
                         l_bl_OTHER_REJECTION_CODE_tbl,
                         l_bl_CODE_COMBINATION_ID_tbl,
                         l_bl_CCID_GEN_STATUS_CODE_tbl,
                         l_bl_CCID_GEN_REJ_MESSAGE_tbl,
                         l_bl_REQUEST_ID_tbl,
                         l_bl_BORROWED_REVENUE_tbl,
                         l_bl_TP_REVENUE_IN_tbl,
                         l_bl_TP_REVENUE_OUT_tbl,
                         l_bl_REVENUE_ADJ_tbl,
                         l_bl_LENT_RESOURCE_COST_tbl,
                         l_bl_TP_COST_IN_tbl,
                         l_bl_TP_COST_OUT_tbl,
                         l_bl_COST_ADJ_tbl,
                         l_bl_UNASSIGNED_TIME_COST_tbl,
                         l_bl_UTILIZATION_PERCENT_tbl,
                         l_bl_UTILIZATION_HOURS_tbl,
                         l_bl_UTILIZATION_ADJ_tbl,
                         l_bl_CAPACITY_tbl,
                         l_bl_HEAD_COUNT_tbl,
                         l_bl_HEAD_COUNT_ADJ_tbl,
                         l_bl_PROJFUNC_CUR_CODE_tbl,
                         l_bl_PROJFUNC_COST_RAT_TYP_tbl,
                         l_bl_PJFN_COST_RAT_DAT_TYP_tbl,
                         l_bl_PROJFUNC_COST_RAT_DAT_tbl,
                         l_bl_PROJFUNC_REV_RATE_TYP_tbl,
                         l_bl_PJFN_REV_RAT_DAT_TYPE_tbl,
                         l_bl_PROJFUNC_REV_RAT_DATE_tbl,
                         l_bl_PROJECT_COST_RAT_TYPE_tbl,
                         l_bl_PROJ_COST_RAT_DAT_TYP_tbl,
                         l_bl_PROJ_COST_RATE_DATE_tbl,
                         l_bl_PROJECT_RAW_COST_tbl,
                         l_bl_PROJECT_BURDENED_COST_tbl,
                         l_bl_PROJECT_REV_RATE_TYPE_tbl,
                         l_bl_PRJ_REV_RAT_DATE_TYPE_tbl,
                         l_bl_PROJECT_REV_RATE_DATE,
                         l_bl_PROJECT_REVENUE_tbl,
                         l_bl_TXN_CURRENCY_CODE_tbl,
                         l_bl_TXN_RAW_COST_tbl,
                         l_bl_TXN_BURDENED_COST_tbl,
                         l_bl_TXN_REVENUE_tbl,
                         l_bl_BUCKETING_PERIOD_CODE_tbl,
                         l_bl_TXN_STD_COST_RATE_tbl,
                         l_bl_TXN_COST_RATE_OVERIDE_tbl,
                         l_bl_COST_IND_CMPLD_SET_ID_tbl,
                      --     l_bl_TXN_BURDEN_MULTIPLIER_tbl,
                      --     l_bl_TXN_BRD_MLTIPLI_OVRID_tbl,
                         l_bl_TXN_STD_BILL_RATE_tbl,
                         l_bl_TXN_BILL_RATE_OVERRID_tbl,
                         l_bl_TXN_MARKUP_PERCENT_tbl,
                         l_bl_TXN_MRKUP_PER_OVERIDE_tbl,
                         l_bl_TXN_DISC_PERCENTAGE_tbl,
                         l_bl_TRANSFER_PRICE_RATE_tbl,
                         l_bl_BURDEN_COST_RATE_tbl,
                         l_bl_BURDEN_COST_RAT_OVRID_tbl,
                         l_bl_PC_CUR_CONV_REJ_CODE_tbl,
                         l_bl_PFC_CUR_CONV_REJ_CODE_tbl
                        from   pa_budget_lines pbls,
                             pa_budget_lines pblt
                        where  get_mapped_dml_code(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)='UPDATE'
                        and    pbls.budget_version_id = l_src_ver_id_tbl(j)
                        and    pblt.budget_version_id(+) = p_budget_version_id
                        and    pblt.resource_assignment_id(+)=get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code)
                        AND    pblt.txn_currency_code(+)=DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,
                                                      DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
                        AND    pblt.start_date(+)=pbls.start_date
                        --IPM Arch Enhancement Bug 4865563
                      /*and    pbls.cost_rejection_code IS NULL
                        and    pbls.revenue_rejection_code IS NULL
                        and    pbls.burden_rejection_code IS NULL
                        and    pbls.other_rejection_code IS NULL
                        and    pbls.pc_cur_conv_rejection_code IS NULL
                        and    pbls.pfc_cur_conv_rejection_code IS NULL*/
                        and    pbls.start_date >= nvl(l_etc_start_date,pbls.start_date)
                        GROUP BY get_mapped_ra_id(null,null,pbls.resource_assignment_id,l_targ_plan_level_code), DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code)
                              ,pbls.start_date, pbls.period_name,pbls.end_date,pblt.resource_assignment_id,
                              pblt.start_Date,pblt.txn_currency_code;
Line: 9016

                         pa_debug.g_err_stage:='selected bls for PA/GL TP and same resource list';
Line: 9024

                      SELECT get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id),
                           decode(pblt.resource_assignment_id,null, 'INSERT',
                                                      decode(pblt.txn_currency_code, null,'INSERT',
                                                           decode(pblt.start_date,null,'INSERT','UPDATE'))),
                           pbls.start_date,
                           pbls.end_date,
                           pbls.period_name,
                           decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                              decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)),
                           sum(Decode(l_cost_impl_flag ,'Y', pbls.raw_cost, null)),
                           sum(Decode(l_cost_impl_flag ,'Y', pbls.burdened_cost,null)),
                           sum(Decode(l_rev_impl_flag ,'Y', pbls.revenue,null))*l_partial_factor,
                           decode(count(pbls.budget_line_id),1,max(pbls.change_reason_code),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.description),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute_category),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute1),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute2),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute3),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute4),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute5),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute6),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute7),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute8),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute9),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute10),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute11),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute12),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute13),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute14),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.attribute15),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.pm_product_code),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.pm_budget_line_reference),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.cost_rejection_code),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.revenue_rejection_code),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.burden_rejection_code),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.other_rejection_code),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.code_combination_id),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.ccid_gen_status_code),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.CCID_GEN_REJ_MESSAGE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.REQUEST_ID),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.BORROWED_REVENUE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_IN),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.TP_REVENUE_OUT),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.REVENUE_ADJ),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.LENT_RESOURCE_COST),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_IN),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.TP_COST_OUT),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.COST_ADJ),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.UNASSIGNED_TIME_COST),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_PERCENT),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_HOURS),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.UTILIZATION_ADJ),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.CAPACITY),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.HEAD_COUNT_ADJ),null),
                           l_projfunc_currency_code,
                           DECODE(l_cost_impl_flag,'Y', DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE_TYPE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_COST_RATE_DATE),null),
                           Decode(l_rev_impl_flag,'Y',DECODE(l_targ_multi_curr_flag,'Y', 'User', null),Null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE_TYPE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PROJFUNC_REV_RATE_DATE),null),
                           DECODE(l_cost_impl_flag,'Y',DECODE(l_targ_multi_curr_flag, 'Y','User', null),Null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE_TYPE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_COST_RATE_DATE),null),
                           sum(Decode(l_cost_impl_flag ,'Y',pbls.project_raw_cost,null)),
                           sum(Decode(l_cost_impl_flag ,'Y',pbls.project_burdened_cost,null)),
                           Decode(l_rev_impl_flag, 'Y', DECODE(l_targ_multi_curr_flag, 'Y', 'User', null),Null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE_TYPE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PROJECT_REV_RATE_DATE),null),
                           sum(Decode(l_rev_impl_flag , 'Y', pbls.project_revenue,null))*l_partial_factor,
                           DECODE(l_copy_pfc_for_txn_amt_flag,'Y',l_projfunc_currency_code,DECODE(l_same_multi_curr_flag,'Y', pbls.txn_currency_code,l_project_currency_code)),


                           --Bug 4224757.. Code changes for bug#4224757 starts here
                           SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0),
                           DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))))),
                           SUM(decode(l_cost_impl_flag,'Y', decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0),
                           DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_burdened_cost,0),
                           nvl(pbls.project_burdened_cost,0))))) ,
                           SUM(decode(l_rev_impl_flag,'Y',decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.revenue,0),
                           DECODE(l_same_multi_curr_flag, 'Y', nvl(pbls.txn_revenue,0),
                           nvl(pbls.project_revenue,0)))))*l_partial_factor ,
                           --Bug 4224757.. Code changes for bug#4224757 ends here


                           decode(count(pbls.budget_line_id),1,max(pbls.BUCKETING_PERIOD_CODE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_cost_rate),null),

                           --Bug 4224757. Code changes for bug#4224757 starts here
                           decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                           decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.raw_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                            nvl(pbls.txn_raw_cost,0), nvl(pbls.project_raw_cost,0))) ))/
                           decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                       decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null)))  ,
                           --Bug 4224757. Code changes for bug#4224757 ends here

                           decode(count(pbls.budget_line_id),1,max(pbls.cost_ind_compiled_set_id),null),
                      --      decode(count(pbls.budget_line_id),1,max(pbls.txn_burden_multiplier),null),

                           decode(count(pbls.budget_line_id),1,max(pbls.txn_standard_bill_rate),null),

                           --Bug 4224757. Code changes for bug#4224757 starts here
                           decode(nvl(sum(pbls.quantity),0),0,0,sum(Decode(l_rev_impl_flag ,'Y',
                                decode(l_copy_pfc_for_txn_amt_flag,'Y', nvl(pbls.revenue,0), DECODE(l_same_multi_curr_flag,
                                   'Y', nvl(pbls.txn_revenue,0), nvl(pbls.project_revenue,0)))))*l_partial_factor/
                           decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                                decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))),
                           --Bug 4224757. Code changes for bug#4224757 ends here

                           decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.TXN_MARKUP_PERCENT_OVERRIDE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.TXN_DISCOUNT_PERCENTAGE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.TRANSFER_PRICE_RATE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.BURDEN_COST_RATE),null),

                           --Bug 4224757. Code changes for bug#4224757 starts here
                           decode(nvl(sum(pbls.quantity),0),0,0,SUM(decode(l_cost_impl_flag,'Y',
                           decode(l_copy_pfc_for_txn_amt_flag,'Y',nvl(pbls.burdened_cost,0), DECODE(l_same_multi_curr_flag, 'Y',
                           nvl(pbls.txn_burdened_cost,0), nvl(pbls.project_burdened_cost,0))) ))/
                           decode(l_cost_impl_flag,'Y',sum(pbls.quantity),decode(l_rev_impl_flag,'Y',
                                                             decode(l_impl_qty_tbl(j),'Y', sum(pbls.quantity) * l_partial_factor,null),null))) ,
                           --Bug 4224757. Code changes for bug#4224757 ends here

                           decode(count(pbls.budget_line_id),1,max(pbls.PC_CUR_CONV_REJECTION_CODE),null),
                           decode(count(pbls.budget_line_id),1,max(pbls.PFC_CUR_CONV_REJECTION_CODE),null)
                      BULK COLLECT INTO
                            l_bl_RESOURCE_ASIGNMENT_ID_tbl,
                            l_upd_ra_bl_dml_code_tbl,
                            l_bl_START_DATE_tbl,
                            l_bl_END_DATE_tbl,
                            l_bl_PERIOD_NAME_tbl,
                            l_bl_QUANTITY_tbl,
                            l_bl_RAW_COST_tbl,
                            l_bl_BURDENED_COST_tbl,
                            l_bl_REVENUE_tbl,
                            l_bl_CHANGE_REASON_CODE_tbl,
                            l_bl_DESCRIPTION_tbl,
                            l_bl_ATTRIBUTE_CATEGORY_tbl,
                            l_bl_ATTRIBUTE1_tbl,
                            l_bl_ATTRIBUTE2_tbl,
                            l_bl_ATTRIBUTE3_tbl,
                            l_bl_ATTRIBUTE4_tbl,
                            l_bl_ATTRIBUTE5_tbl,
                            l_bl_ATTRIBUTE6_tbl,
                            l_bl_ATTRIBUTE7_tbl,
                            l_bl_ATTRIBUTE8_tbl,
                            l_bl_ATTRIBUTE9_tbl,
                            l_bl_ATTRIBUTE10_tbl,
                            l_bl_ATTRIBUTE11_tbl,
                            l_bl_ATTRIBUTE12_tbl,
                            l_bl_ATTRIBUTE13_tbl,
                            l_bl_ATTRIBUTE14_tbl,
                            l_bl_ATTRIBUTE15_tbl,
                            l_bl_PM_PRODUCT_CODE_tbl,
                            l_bl_PM_BUDGET_LINE_REF_tbl,
                            l_bl_COST_REJECTION_CODE_tbl,
                            l_bl_REVENUE_REJ_CODE_tbl,
                            l_bl_BURDEN_REJECTION_CODE_tbl,
                            l_bl_OTHER_REJECTION_CODE_tbl,
                            l_bl_CODE_COMBINATION_ID_tbl,
                            l_bl_CCID_GEN_STATUS_CODE_tbl,
                            l_bl_CCID_GEN_REJ_MESSAGE_tbl,
                            l_bl_REQUEST_ID_tbl,
                            l_bl_BORROWED_REVENUE_tbl,
                            l_bl_TP_REVENUE_IN_tbl,
                            l_bl_TP_REVENUE_OUT_tbl,
                            l_bl_REVENUE_ADJ_tbl,
                            l_bl_LENT_RESOURCE_COST_tbl,
                            l_bl_TP_COST_IN_tbl,
                            l_bl_TP_COST_OUT_tbl,
                            l_bl_COST_ADJ_tbl,
                            l_bl_UNASSIGNED_TIME_COST_tbl,
                            l_bl_UTILIZATION_PERCENT_tbl,
                            l_bl_UTILIZATION_HOURS_tbl,
                            l_bl_UTILIZATION_ADJ_tbl,
                            l_bl_CAPACITY_tbl,
                            l_bl_HEAD_COUNT_tbl,
                            l_bl_HEAD_COUNT_ADJ_tbl,
                            l_bl_PROJFUNC_CUR_CODE_tbl,
                            l_bl_PROJFUNC_COST_RAT_TYP_tbl,
                            l_bl_PJFN_COST_RAT_DAT_TYP_tbl,
                            l_bl_PROJFUNC_COST_RAT_DAT_tbl,
                            l_bl_PROJFUNC_REV_RATE_TYP_tbl,
                            l_bl_PJFN_REV_RAT_DAT_TYPE_tbl,
                            l_bl_PROJFUNC_REV_RAT_DATE_tbl,
                            l_bl_PROJECT_COST_RAT_TYPE_tbl,
                            l_bl_PROJ_COST_RAT_DAT_TYP_tbl,
                            l_bl_PROJ_COST_RATE_DATE_tbl,
                            l_bl_PROJECT_RAW_COST_tbl,
                            l_bl_PROJECT_BURDENED_COST_tbl,
                            l_bl_PROJECT_REV_RATE_TYPE_tbl,
                            l_bl_PRJ_REV_RAT_DATE_TYPE_tbl,
                            l_bl_PROJECT_REV_RATE_DATE,
                            l_bl_PROJECT_REVENUE_tbl,
                            l_bl_TXN_CURRENCY_CODE_tbl,
                            l_bl_TXN_RAW_COST_tbl,
                            l_bl_TXN_BURDENED_COST_tbl,
                            l_bl_TXN_REVENUE_tbl,
                            l_bl_BUCKETING_PERIOD_CODE_tbl,
                            l_bl_TXN_STD_COST_RATE_tbl,
                            l_bl_TXN_COST_RATE_OVERIDE_tbl,
                            l_bl_COST_IND_CMPLD_SET_ID_tbl,
                         --     l_bl_TXN_BURDEN_MULTIPLIER_tbl,
                         --     l_bl_TXN_BRD_MLTIPLI_OVRID_tbl,
                            l_bl_TXN_STD_BILL_RATE_tbl,
                            l_bl_TXN_BILL_RATE_OVERRID_tbl,
                            l_bl_TXN_MARKUP_PERCENT_tbl,
                            l_bl_TXN_MRKUP_PER_OVERIDE_tbl,
                            l_bl_TXN_DISC_PERCENTAGE_tbl,
                            l_bl_TRANSFER_PRICE_RATE_tbl,
                            l_bl_BURDEN_COST_RATE_tbl,
                            l_bl_BURDEN_COST_RAT_OVRID_tbl,
                            l_bl_PC_CUR_CONV_REJ_CODE_tbl,
                            l_bl_PFC_CUR_CONV_REJ_CODE_tbl
                      from   pa_budget_lines pblt,
                           (SELECT  pbls.resource_assignment_id
                                 ,pbls.start_date
                                 ,pbls.last_update_date
                                 ,pbls.last_updated_by
                                 ,pbls.creation_date
                                 ,pbls.created_by
                                 ,pbls.last_update_login
                                 ,pbls.end_date
                                 ,pbls.period_name
                                 ,pbls.quantity
                                 ,pbls.raw_cost
                                 ,pbls.burdened_cost
                                 ,pbls.revenue
                                 ,pbls.change_reason_code
                                 ,pbls.description
                                 ,pbls.attribute_category
                                 ,pbls.attribute1
                                 ,pbls.attribute2
                                 ,pbls.attribute3
                                 ,pbls.attribute4
                                 ,pbls.attribute5
                                 ,pbls.attribute6
                                 ,pbls.attribute7
                                 ,pbls.attribute8
                                 ,pbls.attribute9
                                 ,pbls.attribute10
                                 ,pbls.attribute11
                                 ,pbls.attribute12
                                 ,pbls.attribute13
                                 ,pbls.attribute14
                                 ,pbls.attribute15
                                 ,pbls.raw_cost_source
                                 ,pbls.burdened_cost_source
                                 ,pbls.quantity_source
                                 ,pbls.revenue_source
                                 ,pbls.pm_product_code
                                 ,pbls.pm_budget_line_reference
                                 ,pbls.cost_rejection_code
                                 ,pbls.revenue_rejection_code
                                 ,pbls.burden_rejection_code
                                 ,pbls.other_rejection_code
                                 ,pbls.code_combination_id
                                 ,pbls.ccid_gen_status_code
                                 ,pbls.ccid_gen_rej_message
                                 ,pbls.request_id
                                 ,pbls.borrowed_revenue
                                 ,pbls.tp_revenue_in
                                 ,pbls.tp_revenue_out
                                 ,pbls.revenue_adj
                                 ,pbls.lent_resource_cost
                                 ,pbls.tp_cost_in
                                 ,pbls.tp_cost_out
                                 ,pbls.cost_adj
                                 ,pbls.unassigned_time_cost
                                 ,pbls.utilization_percent
                                 ,pbls.utilization_hours
                                 ,pbls.utilization_adj
                                 ,pbls.capacity
                                 ,pbls.head_count
                                 ,pbls.head_count_adj
                                 ,pbls.projfunc_currency_code
                                 ,pbls.projfunc_cost_rate_type
                                 ,pbls.projfunc_cost_exchange_rate
                                 ,pbls.projfunc_cost_rate_date_type
                                 ,pbls.projfunc_cost_rate_date
                                 ,pbls.projfunc_rev_rate_type
                                 ,pbls.projfunc_rev_exchange_rate
                                 ,pbls.projfunc_rev_rate_date_type
                                 ,pbls.projfunc_rev_rate_date
                                 ,pbls.project_currency_code
                                 ,pbls.project_cost_rate_type
                                 ,pbls.project_cost_exchange_rate
                                 ,pbls.project_cost_rate_date_type
                                 ,pbls.project_cost_rate_date
                                 ,pbls.project_raw_cost
                                 ,pbls.project_burdened_cost
                                 ,pbls.project_rev_rate_type
                                 ,pbls.project_rev_exchange_rate
                                 ,pbls.project_rev_rate_date_type
                                 ,pbls.project_rev_rate_date
                                 ,pbls.project_revenue
                                 ,pbls.txn_currency_code
                                 ,pbls.txn_raw_cost
                                 ,pbls.txn_burdened_cost
                                 ,pbls.txn_revenue
                                 ,pbls.bucketing_period_code
                                 ,pbls.budget_line_id
                                 ,pbls.budget_version_id
                                 ,pbls.txn_standard_cost_rate
                                 ,pbls.txn_cost_rate_override
                                 ,pbls.cost_ind_compiled_set_id
                                 ,pbls.txn_standard_bill_rate
                                 ,pbls.txn_bill_rate_override
                                 ,pbls.txn_markup_percent
                                 ,pbls.txn_markup_percent_override
                                 ,pbls.txn_discount_percentage
                                 ,pbls.transfer_price_rate
                                 ,pbls.burden_cost_rate
                                 ,pbls.burden_cost_rate_override
                                 ,pbls.pc_cur_conv_rejection_code
                                 ,pbls.pfc_cur_conv_rejection_code
                                 ,pras.resource_assignment_id
                                 ,pras.task_id
                                 ,tmp4.resource_list_member_id
                             FROM   pa_resource_assignments pras,
                                  pa_res_list_map_tmp4 tmp4,
                                  pa_budget_lines pbls
                             WHERE  tmp4.txn_source_id=pras.resource_assignment_id
                             AND    pbls.resource_assignment_id=pras.resource_assignment_id) pbls
                      where  get_mapped_dml_code(get_task_id(l_targ_plan_level_code,pbls.task_id),pbls.resource_list_member_id)='UPDATE'
                      and    pblt.budget_version_id(+) = p_budget_version_id
                      and    pblt.resource_assignment_id(+)=get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id)
                      AND    pblt.txn_currency_code(+)=DECODE(l_copy_pfc_for_txn_amt_flag,'Y', l_projfunc_currency_code,
                                                    DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code))
                      AND    pblt.start_date(+)=pbls.start_date
                      --IPM Arch Enhancement Bug 4865563
                    /*and    pbls.cost_rejection_code IS NULL
                      and    pbls.revenue_rejection_code IS NULL
                      and    pbls.burden_rejection_code IS NULL
                      and    pbls.other_rejection_code IS NULL
                      and    pbls.pc_cur_conv_rejection_code IS NULL
                      and    pbls.pfc_cur_conv_rejection_code IS NULL*/
                      and    pbls.start_date >= nvl(l_etc_start_date,pbls.start_date)
                      GROUP BY get_mapped_ra_id(get_task_id(l_targ_plan_level_code,pbls.task_id), pbls.resource_list_member_id), DECODE(l_same_multi_curr_flag, 'Y', pbls.txn_currency_code,l_project_currency_code)
                      ,pbls.start_date,pbls.end_date,pbls.period_name,pblt.resource_assignment_id,pblt.txn_currency_code,pblt.start_date;
Line: 9406

                          SELECT agr.agreement_id,
                                 agr.agreement_currency_code
                          INTO   l_agreement_id,
                                 l_agreement_currency_code
                          FROM   pa_budget_versions cibv,
                                 pa_agreements_all  agr
                          WHERE  cibv.budget_version_id = l_src_ver_id_tbl(j)
                          AND    cibv.agreement_id = agr.agreement_id;
Line: 9452

                        INSERT INTO PA_BUDGET_LINES(RESOURCE_ASSIGNMENT_ID,
                                   START_DATE,
                                   LAST_UPDATE_DATE,
                                   LAST_UPDATED_BY,
                                   CREATION_DATE,
                                   CREATED_BY,
                                   LAST_UPDATE_LOGIN,
                                   END_DATE,
                                   PERIOD_NAME,
                                   QUANTITY,
                                   RAW_COST,
                                   BURDENED_COST,
                                   REVENUE,
                                   CHANGE_REASON_CODE,
                                   DESCRIPTION,
                                   ATTRIBUTE_CATEGORY,
                                   ATTRIBUTE1,
                                   ATTRIBUTE2,
                                   ATTRIBUTE3,
                                   ATTRIBUTE4,
                                   ATTRIBUTE5,
                                   ATTRIBUTE6,
                                   ATTRIBUTE7,
                                   ATTRIBUTE8,
                                   ATTRIBUTE9,
                                   ATTRIBUTE10,
                                   ATTRIBUTE11,
                                   ATTRIBUTE12,
                                   ATTRIBUTE13,
                                   ATTRIBUTE14,
                                   ATTRIBUTE15,
                                   RAW_COST_SOURCE,
                                   BURDENED_COST_SOURCE,
                                   QUANTITY_SOURCE,
                                   REVENUE_SOURCE,
                                   PM_PRODUCT_CODE,
                                   PM_BUDGET_LINE_REFERENCE,
                                   COST_REJECTION_CODE,
                                   REVENUE_REJECTION_CODE,
                                   BURDEN_REJECTION_CODE,
                                   OTHER_REJECTION_CODE,
                                   CODE_COMBINATION_ID,
                                   CCID_GEN_STATUS_CODE,
                                   CCID_GEN_REJ_MESSAGE,
                                   REQUEST_ID,
                                   BORROWED_REVENUE,
                                   TP_REVENUE_IN,
                                   TP_REVENUE_OUT,
                                   REVENUE_ADJ,
                                   LENT_RESOURCE_COST,
                                   TP_COST_IN,
                                   TP_COST_OUT,
                                   COST_ADJ,
                                   UNASSIGNED_TIME_COST,
                                   UTILIZATION_PERCENT,
                                   UTILIZATION_HOURS,
                                   UTILIZATION_ADJ,
                                   CAPACITY,
                                   HEAD_COUNT,
                                   HEAD_COUNT_ADJ,
                                   PROJFUNC_CURRENCY_CODE,
                                   PROJFUNC_COST_RATE_TYPE,
                                   PROJFUNC_COST_EXCHANGE_RATE,
                                   PROJFUNC_COST_RATE_DATE_TYPE,
                                   PROJFUNC_COST_RATE_DATE,
                                   PROJFUNC_REV_RATE_TYPE,
                                   PROJFUNC_REV_EXCHANGE_RATE,
                                   PROJFUNC_REV_RATE_DATE_TYPE,
                                   PROJFUNC_REV_RATE_DATE,
                                   PROJECT_CURRENCY_CODE,
                                   PROJECT_COST_RATE_TYPE,
                                   PROJECT_COST_EXCHANGE_RATE,
                                   PROJECT_COST_RATE_DATE_TYPE,
                                   PROJECT_COST_RATE_DATE,
                                   PROJECT_RAW_COST,
                                   PROJECT_BURDENED_COST,
                                   PROJECT_REV_RATE_TYPE,
                                   PROJECT_REV_EXCHANGE_RATE,
                                   PROJECT_REV_RATE_DATE_TYPE,
                                   PROJECT_REV_RATE_DATE,
                                   PROJECT_REVENUE,
                                   TXN_CURRENCY_CODE,
                                   TXN_RAW_COST,
                                   TXN_BURDENED_COST,
                                   TXN_REVENUE,
                                   BUCKETING_PERIOD_CODE,
                                   BUDGET_LINE_ID,
                                   BUDGET_VERSION_ID,
                                   TXN_STANDARD_COST_RATE,
                                   TXN_COST_RATE_OVERRIDE,
                                   COST_IND_COMPILED_SET_ID,
                              --     TXN_BURDEN_MULTIPLIER,
                              --     TXN_BURDEN_MULTIPLIER_OVERRIDE,
                                   TXN_STANDARD_BILL_RATE,
                                   TXN_BILL_RATE_OVERRIDE,
                                   TXN_MARKUP_PERCENT,
                                   TXN_MARKUP_PERCENT_OVERRIDE,
                                   TXN_DISCOUNT_PERCENTAGE,
                                   TRANSFER_PRICE_RATE,
                                   BURDEN_COST_RATE,
                                   BURDEN_COST_RATE_OVERRIDE,
                                   PC_CUR_CONV_REJECTION_CODE,
                                   PFC_CUR_CONV_REJECTION_CODE
                                   )
                             SELECT l_bl_RESOURCE_ASIGNMENT_ID_tbl(kk),
                                  l_bl_START_DATE_tbl(kk),
                                  sysdate,
                                  fnd_global.user_id,
                                  sysdate,
                                  fnd_global.user_id,
                                  fnd_global.login_id,
                                  l_bl_END_DATE_tbl(kk),
                                  l_bl_PERIOD_NAME_tbl(kk),
                                  Decode(l_bl_rbf_flag_tbl(kk),
                                         'N',Decode(l_target_version_type,
                                                    'REVENUE',l_bl_TXN_REVENUE_tbl(kk),
                                                              l_bl_TXN_RAW_COST_tbl(kk)),
                                          l_bl_QUANTITY_tbl(kk)),
                                  l_bl_RAW_COST_tbl(kk),
                                  l_bl_BURDENED_COST_tbl(kk),
                                  l_bl_REVENUE_tbl(kk),
                                  l_bl_CHANGE_REASON_CODE_tbl(kk),
                                  l_bl_DESCRIPTION_tbl(kk),
                                  l_bl_ATTRIBUTE_CATEGORY_tbl(kk),
                                  l_bl_ATTRIBUTE1_tbl(kk),
                                  l_bl_ATTRIBUTE2_tbl(kk),
                                  l_bl_ATTRIBUTE3_tbl(kk),
                                  l_bl_ATTRIBUTE4_tbl(kk),
                                  l_bl_ATTRIBUTE5_tbl(kk),
                                  l_bl_ATTRIBUTE6_tbl(kk),
                                  l_bl_ATTRIBUTE7_tbl(kk),
                                  l_bl_ATTRIBUTE8_tbl(kk),
                                  l_bl_ATTRIBUTE9_tbl(kk),
                                  l_bl_ATTRIBUTE10_tbl(kk),
                                  l_bl_ATTRIBUTE11_tbl(kk),
                                  l_bl_ATTRIBUTE12_tbl(kk),
                                  l_bl_ATTRIBUTE13_tbl(kk),
                                  l_bl_ATTRIBUTE14_tbl(kk),
                                  l_bl_ATTRIBUTE15_tbl(kk),
                                  'I',
                                  'I',
                                  'I',
                                  'I',
                                  l_bl_PM_PRODUCT_CODE_tbl(kk),
                                  l_bl_PM_BUDGET_LINE_REF_tbl(kk),
                                  l_bl_COST_REJECTION_CODE_tbl(kk),
                                  l_bl_REVENUE_REJ_CODE_tbl(kk),
                                  l_bl_BURDEN_REJECTION_CODE_tbl(kk),
                                  l_bl_OTHER_REJECTION_CODE_tbl(kk),
                                  l_bl_CODE_COMBINATION_ID_tbl(kk),
                                  l_bl_CCID_GEN_STATUS_CODE_tbl(kk),
                                  l_bl_CCID_GEN_REJ_MESSAGE_tbl(kk),
                                  l_bl_REQUEST_ID_tbl(kk),
                                  l_bl_BORROWED_REVENUE_tbl(kk),
                                  l_bl_TP_REVENUE_IN_tbl(kk),
                                  l_bl_TP_REVENUE_OUT_tbl(kk),
                                  l_bl_REVENUE_ADJ_tbl(kk),
                                  l_bl_LENT_RESOURCE_COST_tbl(kk),
                                  l_bl_TP_COST_IN_tbl(kk),
                                  l_bl_TP_COST_OUT_tbl(kk),
                                  l_bl_COST_ADJ_tbl(kk),
                                  l_bl_UNASSIGNED_TIME_COST_tbl(kk),
                                  l_bl_UTILIZATION_PERCENT_tbl(kk),
                                  l_bl_UTILIZATION_HOURS_tbl(kk),
                                  l_bl_UTILIZATION_ADJ_tbl(kk),
                                  l_bl_CAPACITY_tbl(kk),
                                  l_bl_HEAD_COUNT_tbl(kk),
                                  l_bl_HEAD_COUNT_ADJ_tbl(kk),
                                  l_bl_PROJFUNC_CUR_CODE_tbl(kk),
                                  l_bl_PROJFUNC_COST_RAT_TYP_tbl(kk),
                                  DECODE(l_bl_PROJFUNC_COST_RAT_TYP_tbl(kk),'User', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
                                          'B', nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0)),0,0,(decode(l_report_cost_using,'R',nvl(l_bl_RAW_COST_tbl(kk),0),
                                          'B',nvl(l_bl_BURDENED_COST_tbl(kk),0)) / (decode(l_report_cost_using,'R',nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
                                          'B', nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0))))),Null),Null), -- Bug 3839273
                                  l_bl_PJFN_COST_RAT_DAT_TYP_tbl(kk),
                                  l_bl_PROJFUNC_COST_RAT_DAT_tbl(kk),
                                  l_bl_PROJFUNC_REV_RATE_TYP_tbl(kk),
                                  Decode(l_bl_PROJFUNC_REV_RATE_TYP_tbl(kk),'User',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(l_bl_TXN_REVENUE_tbl(kk),0),0,0,nvl(l_bl_REVENUE_tbl(kk),0) /
                                         nvl(l_bl_TXN_REVENUE_tbl(kk),0)),Null),Null), -- Bug 3839273
                                  l_bl_PJFN_REV_RAT_DAT_TYPE_tbl(kk),
                                  l_bl_PROJFUNC_REV_RAT_DATE_tbl(kk),
                                  l_project_currency_code,
                                  l_bl_PROJECT_COST_RAT_TYPE_tbl(kk),
                                  DECODE(l_bl_PROJECT_COST_RAT_TYPE_tbl(kk),'User', DECODE(l_targ_multi_curr_flag,'Y', Decode(decode(l_report_cost_using, 'R',nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
                                        'B', nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0)),0,0,(decode(l_report_cost_using,'R',nvl(l_bl_PROJECT_RAW_COST_tbl(kk),0),
                                        'B',nvl(l_bl_PROJECT_BURDENED_COST_tbl(kk),0)) / (decode(l_report_cost_using,'R',nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
                                        'B',nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0))))),Null),Null), -- Bug 3839273
                                  l_bl_PROJ_COST_RAT_DAT_TYP_tbl(kk),
                                  l_bl_PROJ_COST_RATE_DATE_tbl(kk),
                                  l_bl_PROJECT_RAW_COST_tbl(kk),
                                  l_bl_PROJECT_BURDENED_COST_tbl(kk),
                                  l_bl_PROJECT_REV_RATE_TYPE_tbl(kk),
                                  Decode(l_bl_PROJECT_REV_RATE_TYPE_tbl(kk),'User',DECODE(l_targ_multi_curr_flag,'Y', Decode(nvl(l_bl_TXN_REVENUE_tbl(kk),0),0,0,nvl(l_bl_PROJECT_REVENUE_tbl(kk),0) /
                                         nvl(l_bl_TXN_REVENUE_tbl(kk),0)),Null),Null), -- Bug 3839273
                                  l_bl_PRJ_REV_RAT_DATE_TYPE_tbl(kk),
                                  l_bl_PROJECT_REV_RATE_DATE(kk),
                                  l_bl_PROJECT_REVENUE_tbl(kk),
                                  l_bl_TXN_CURRENCY_CODE_tbl(kk),
                                  l_bl_TXN_RAW_COST_tbl(kk),
                                  l_bl_TXN_BURDENED_COST_tbl(kk),
                                  l_bl_TXN_REVENUE_tbl(kk),
                                  l_bl_BUCKETING_PERIOD_CODE_tbl(kk),
                                  pa_budget_lines_s.nextval,
                                  p_budget_version_id,
                                  l_bl_TXN_STD_COST_RATE_tbl(kk),
                                  DECODE(l_target_version_type,
                                       'REVENUE',l_bl_TXN_COST_RATE_OVERIDE_tbl(kk),
                                        DECODE(l_bl_rbf_flag_tbl(kk),
                                               'N',1,
                                               l_bl_TXN_COST_RATE_OVERIDE_tbl(kk))),
                                  l_bl_COST_IND_CMPLD_SET_ID_tbl(kk),
                              --      l_bl_TXN_BURDEN_MULTIPLIER_tbl(kk),
                              --      l_bl_TXN_BRD_MLTIPLI_OVRID_tbl(kk),
                                  l_bl_TXN_STD_BILL_RATE_tbl(kk),
                                  DECODE(l_target_version_type,
                                         'REVENUE',DECODE(l_bl_rbf_flag_tbl(kk),
                                                          'N',1,
                                                           l_bl_TXN_BILL_RATE_OVERRID_tbl(kk)),
                                         l_bl_TXN_BILL_RATE_OVERRID_tbl(kk)),
                                  l_bl_TXN_MARKUP_PERCENT_tbl(kk),
                                  l_bl_TXN_MRKUP_PER_OVERIDE_tbl(kk),
                                  l_bl_TXN_DISC_PERCENTAGE_tbl(kk),
                                  l_bl_TRANSFER_PRICE_RATE_tbl(kk),
                                  l_bl_BURDEN_COST_RATE_tbl(kk),
                                  DECODE(l_target_version_type,
                                       'REVENUE',l_bl_BURDEN_COST_RAT_OVRID_tbl(kk),
                                        DECODE(l_bl_rbf_flag_tbl(kk),
                                             'Y',l_bl_BURDEN_COST_RAT_OVRID_tbl(kk),
                                             DECODE(nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
                                                    0,null,
                                                    l_bl_TXN_BURDENED_COST_tbl(kk)/l_bl_TXN_RAW_COST_tbl(kk)))),
                                  l_bl_PC_CUR_CONV_REJ_CODE_tbl(kk),
                                  l_bl_PFC_CUR_CONV_REJ_CODE_tbl(kk)
                             from   dual
                             where  l_upd_ra_bl_dml_code_tbl(kk)='INSERT';
Line: 9692

                      UPDATE PA_BUDGET_LINES
                      SET    LAST_UPDATE_DATE=sysdate,
                           LAST_UPDATED_BY=fnd_global.user_id,
                           LAST_UPDATE_LOGIN=fnd_global.login_id,
                           QUANTITY= DECODE(l_bl_rbf_flag_tbl(kk),
                                            'N',DECODE(l_target_version_type,
                                                       'REVENUE',nvl(TXN_REVENUE,0)+ nvl(l_bl_TXN_REVENUE_tbl(kk),0)
                                                                ,nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0)),
                                            nvl(QUANTITY,0)+ nvl(l_bl_QUANTITY_tbl(kk),0)),
                           RAW_COST= nvl(RAW_COST,0) + nvl(l_bl_RAW_COST_tbl(kk),0),
                           BURDENED_COST= nvl(BURDENED_COST,0) + nvl(l_bl_BURDENED_COST_tbl(kk),0),
                           REVENUE= nvl(REVENUE,0) + nvl(l_bl_REVENUE_tbl(kk),0),
                           PROJFUNC_COST_RATE_TYPE= nvl(l_bl_PROJFUNC_COST_RAT_TYP_tbl(kk),PROJFUNC_COST_RATE_TYPE),
                           PROJFUNC_COST_EXCHANGE_RATE= DECODE(nvl(l_bl_PROJFUNC_COST_RAT_TYP_tbl(kk),PROJFUNC_COST_RATE_TYPE),'User', Decode(decode(l_report_cost_using, 'R',nvl(nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),0),
                                                       'B',nvl(nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0),0) ),0,0,
                                                       (decode(l_report_cost_using,'R',nvl(nvl(RAW_COST,0) + nvl(l_bl_RAW_COST_tbl(kk),0),0),
                                                                           'B',nvl(nvl(BURDENED_COST,0) + nvl(l_bl_BURDENED_COST_tbl(kk),0),0)) / decode(l_report_cost_using,'R', nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
                                                                                                    'B', nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0)))),PROJFUNC_COST_EXCHANGE_RATE),
                           PROJFUNC_REV_RATE_TYPE= nvl(l_bl_PROJFUNC_REV_RATE_TYP_tbl(kk),PROJFUNC_REV_RATE_TYPE),
                           PROJFUNC_REV_EXCHANGE_RATE= DECODE(nvl(l_bl_PROJFUNC_REV_RATE_TYP_tbl(kk),PROJFUNC_REV_RATE_TYPE),'User',
                                                      Decode(nvl(nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0),0),0,0,
                                                (nvl(nvl(REVENUE,0) + nvl(l_bl_REVENUE_tbl(kk),0),0) /(nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0)))),PROJFUNC_REV_EXCHANGE_RATE),
                           PROJECT_COST_RATE_TYPE= nvl(l_bl_PROJECT_COST_RAT_TYPE_tbl(kk),PROJECT_COST_RATE_TYPE),
                           PROJECT_COST_EXCHANGE_RATE= DECODE(nvl(l_bl_PROJECT_COST_RAT_TYPE_tbl(kk),PROJECT_COST_RATE_TYPE),'User', Decode(decode(l_report_cost_using, 'R',nvl(nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),0),
                                                       'B',nvl(nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0),0) ),0,0,
                                                       (decode(l_report_cost_using,'R',nvl(nvl(PROJECT_RAW_COST,0) + nvl(l_bl_PROJECT_RAW_COST_tbl(kk),0),0),
                                                                           'B',nvl(nvl(PROJECT_BURDENED_COST,0) + nvl(l_bl_PROJECT_BURDENED_COST_tbl(kk),0),0)) / decode(l_report_cost_using,
                                                                                                    'R', nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
                                                                                                    'B', nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0)))),PROJECT_COST_EXCHANGE_RATE),
                           PROJECT_RAW_COST = nvl(PROJECT_RAW_COST,0) + nvl(l_bl_PROJECT_RAW_COST_tbl(kk),0),
                           PROJECT_BURDENED_COST = nvl(PROJECT_BURDENED_COST,0) + nvl(l_bl_PROJECT_BURDENED_COST_tbl(kk),0),
                           PROJECT_REV_RATE_TYPE = nvl(l_bl_PROJECT_REV_RATE_TYPE_tbl(kk),PROJECT_REV_RATE_TYPE),
                           PROJECT_REV_EXCHANGE_RATE =  DECODE(nvl(l_bl_PROJECT_REV_RATE_TYPE_tbl(kk),PROJECT_REV_RATE_TYPE),'User',
                                                      Decode(nvl(nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0),0),0,0,
                                                      (nvl(nvl(PROJECT_REVENUE,0) + nvl(l_bl_PROJECT_REVENUE_tbl(kk),0),0) /(nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0)))),PROJECT_REV_EXCHANGE_RATE),
                           PROJECT_REVENUE =  nvl(PROJECT_REVENUE,0) + nvl(l_bl_PROJECT_REVENUE_tbl(kk),0),
                           TXN_RAW_COST =  nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0),
                           TXN_BURDENED_COST= nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0),
                           TXN_REVENUE =  nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0),
                           TXN_COST_RATE_OVERRIDE = DECODE(l_target_Version_type,
                                                   'REVENUE', TXN_COST_RATE_OVERRIDE,
                                                   DECODE(l_bl_rbf_flag_tbl(kk),
                                                         'N',1,
                                                         decode((nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)),0,0,((nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0))/
                                                              (nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)))))),
                           BURDEN_COST_RATE_OVERRIDE = DECODE( l_target_Version_type,
                                                       'REVENUE',BURDEN_COST_RATE_OVERRIDE,
                                                       DECODE(l_bl_rbf_flag_tbl(kk),
                                                            'N',decode((nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0)),0,0,((nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0))/
                                                                   (nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0)))),
                                                             decode((nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)),0,0,((nvl(TXN_BURDENED_COST,0) + nvl(l_bl_TXN_BURDENED_COST_tbl(kk),0))/
                                                            (nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)))))),
                           TXN_BILL_RATE_OVERRIDE =  DECODE(l_bl_rbf_flag_tbl(kk),
                                                            'N',DECODE(l_target_version_type,
                                                                       'REVENUE',1,
                                                                        decode((nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0)),0,0,((nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0))/
                                                                                   (nvl(TXN_RAW_COST,0) + nvl(l_bl_TXN_RAW_COST_tbl(kk),0))))),
                                                            decode((nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)),0,0,((nvl(TXN_REVENUE,0) + nvl(l_bl_TXN_REVENUE_tbl(kk),0))/
                                                                   (nvl(QUANTITY,0) + nvl(l_bl_QUANTITY_tbl(kk),0)))))
                       WHERE l_upd_ra_bl_dml_code_tbl(kk) = 'UPDATE'
                       AND   resource_assignment_id       = l_bl_RESOURCE_ASIGNMENT_ID_tbl(kk)
                       AND   start_date                   = l_bl_START_DATE_tbl(kk)
                       AND   txn_currency_code            = l_bl_TXN_CURRENCY_CODE_tbl(kk)
                       RETURNING
                       period_name,
                       txn_currency_code,
                       start_date,
                       end_date,
                       cost_rejection_code,
                       revenue_rejection_code,
                       burden_rejection_code,
                       other_rejection_code,
                       pc_cur_conv_rejection_code,
                       pfc_cur_conv_rejection_code,
                       budget_line_id
                       BULK COLLECT INTO
                       l_upd_period_name_tbl,
                       l_upd_currency_code_tbl,
                       l_upd_bl_start_date_tbl,
                       l_upd_bl_end_date_tbl,
                       l_upd_cost_rejection_code,
                       l_upd_revenue_rejection_code,
                       l_upd_burden_rejection_code,
                       l_upd_other_rejection_code,
                       l_upd_pc_cur_conv_rej_code,
                       l_upd_pfc_cur_conv_rej_code,
                       l_upd_bl_id_tbl;
Line: 9791

                             ,p_bls_inserted_after_id => l_id_before_bl_insertion
                             ,x_return_status         => l_return_status
                             ,x_msg_count             => l_msg_count
                             ,x_msg_data              => l_msg_data);
Line: 9811

                         SELECT nvl(sum(nvl(revenue,0)),0), nvl(sum(nvl(project_revenue,0)),0)
                         INTO   l_targ_pfc_rev_after_merge, l_targ_pc_rev_after_merge
                         FROM   pa_budget_lines
                         WHERE  budget_version_id = p_budget_version_id;
Line: 9928

                             UPDATE pa_budget_lines
                             SET    revenue = nvl(revenue,0) + nvl(l_pfc_revenue_delta,0),
                                    txn_revenue = nvl(revenue,0) + nvl(l_pfc_revenue_delta,0), -- TXN and PFC should be same for AR versions
                                    project_revenue = nvl(project_revenue,0) + nvl(l_pc_revenue_delta,0)
                             WHERE  resource_assignment_id =
                                      get_mapped_ra_id(get_task_id(l_targ_plan_level_code,l_src_delta_amt_adj_task_id),
                                                       l_targ_delta_amt_adj_rlm_id)
                             AND    l_src_delta_amt_adj_start_date  BETWEEN start_date AND end_date
                             AND    budget_version_id = p_budget_version_id
                             AND    rownum < 2 -- not really necessary
                             RETURNING
                             budget_line_id
                             INTO
                             l_rounded_bl_id;
Line: 9946

                                 UPDATE pa_budget_lines
                                 SET    revenue = nvl(revenue,0) + nvl(l_pfc_revenue_delta,0),
                                        txn_revenue = nvl(revenue,0) + nvl(l_pfc_revenue_delta,0), -- TXN and PFC should be same for AR versions
                                        project_revenue = nvl(project_revenue,0) + nvl(l_pc_revenue_delta,0)
                                 WHERE  resource_assignment_id =
                                          get_mapped_ra_id(get_task_id(l_targ_plan_level_code,l_src_delta_amt_adj_task_id),
                                                           l_targ_delta_amt_adj_rlm_id)
                                 AND    budget_version_id = p_budget_version_id
                                 AND    rownum < 2
                                 RETURNING
                                 budget_line_id
                                 INTO
                                 l_rounded_bl_id;
Line: 9984

                                         UPDATE pa_budget_lines
                                         SET    quantity=txn_revenue
                                         WHERE  budget_line_id=l_rounded_bl_id;
Line: 10000

                                SELECT pra.rate_based_flag
                                INTO   l_rounded_bl_rbf
                                FROM   pa_resource_assignments pra,
                                       pa_budget_lines pbl
                                WHERE  pra.resource_assignment_id = pbl.resource_assignment_id
                                AND    pbl.budget_line_id = l_rounded_bl_id;
Line: 10009

                                    UPDATE pa_budget_lines
                                    SET    quantity=txn_revenue
                                    WHERE  budget_line_id=l_rounded_bl_id;
Line: 10043

 	                 merge. Commented out the delete and forall statements below which populate
 	                 pa_fp_spread_calc_tmp with the resource assignment ids and budget version ids
 	                 which will be used by the CheckZeroQtyNegETC api.
 	             */
		     --Check if the budget lines have -Ve ETC because of the change order merge. This need not
                     --not be done when calculate API is called since calculate API internally calls this API
                     --Bug 4395494
		     /*
                     DELETE FROM pa_fp_spread_calc_tmp;
Line: 10054

                        INSERT INTO pa_fp_spread_calc_tmp
                        (budget_version_id,
                         resource_assignment_id)
                        VALUES
                        (p_budget_version_id,
                         l_targ_ra_id_tbl(kk));
Line: 10081

                     SELECT pa_budget_lines_s.currval
                     INTO   l_dummy
                     FROM   dual;
Line: 10085

                     IF l_dummy=l_id_before_bl_insertion THEN

                        l_id_after_bl_insertion := l_id_before_bl_insertion;
Line: 10091

                         SELECT pa_budget_lines_s.nextval
                         INTO   l_id_after_bl_insertion
                         FROM   dual;
Line: 10097

                     IF  l_id_before_bl_insertion <> l_id_after_bl_insertion THEN

                         IF P_PA_DEBUG_MODE = 'Y' THEN
                          pa_debug.g_err_stage:='Preparing input tbls for calculate API';
Line: 10104

                         SELECT pra.resource_assignment_id,
                              'N',
                              'Y',
                              pbl.txn_currency_code,
                              pbl.quantity,
                              pbl.txn_raw_cost,
                              pbl.txn_burdened_cost,
                              pbl.txn_revenue,
                              pbl.start_date,
                              pbl.end_date,
                              pbl.period_name,
                              pbl.project_raw_cost,
                              pbl.project_burdened_cost,
                              pbl.project_revenue,
                              pbl.raw_cost,
                              pbl.burdened_cost,
                              pbl.revenue,
                              pbl.cost_rejection_code,
                              pbl.revenue_rejection_code,
                              pbl.burden_rejection_code,
                              pbl.other_rejection_code,
                              pbl.pc_cur_conv_rejection_code,
                              pbl.pfc_cur_conv_rejection_code,
                              pra.task_id,
                              pra.rbs_element_id,
                              pra.resource_class_code,
                              pra.rate_based_flag
                        BULK COLLECT INTO
                              l_res_assignment_id_tbl,
                              l_delete_budget_lines_tbl,
                              l_spread_amount_flags_tbl,
                              l_currency_code_tbl,
                              l_total_quantity_tbl,
                              l_total_raw_cost_tbl,
                              l_total_burdened_cost_tbl,
                              l_total_revenue_tbl,
                              l_prm_bl_start_date_tbl,
                              l_prm_bl_end_date_tbl,
                              l_period_name_tbl,
                              l_pc_raw_cost_tbl,
                              l_pc_burd_cost_tbl,
                              l_pc_revenue_tbl,
                              l_pfc_raw_cost_tbl,
                              l_pfc_burd_cost_tbl,
                              l_pfc_revenue_tbl,
                              l_cost_rejection_code,
                              l_revenue_rejection_code,
                              l_burden_rejection_code,
                              l_other_rejection_code,
                              l_pc_cur_conv_rejection_code,
                              l_pfc_cur_conv_rejection_code,
                              l_pji_prm_task_id_tbl,
                              l_pji_prm_rbs_elem_id_tbl,
                              l_pji_prm_res_cls_code_tbl,
                              l_pji_prm_rbf_tbl
                        FROM    pa_resource_assignments pra,
                              pa_budget_lines pbl
                        WHERE   pra.resource_assignment_id = pbl.resource_assignment_id
                        AND     (pbl.budget_line_id BETWEEN l_id_before_bl_insertion AND l_id_after_bl_insertion)
                        AND     pra.budget_Version_id=p_budget_version_id;
Line: 10177

                    END IF;--IF  l_id_before_bl_insertion <> l_id_after_bl_insertion THEN
Line: 10192

                          pa_debug.g_err_stage:='Preparing tbls for for the lines that got update';
Line: 10204

                          IF l_upd_ra_bl_dml_code_tbl(kk) = 'UPDATE' THEN

                            l_index:=l_index+1;
Line: 10481

                 * do not have any budget lines would not be inserted into pa_resource_asgn_curr
                 * by the maintenance API. So to insert those left over RAs, we are calling
                 * the following.
                 */
                pa_fin_plan_pub.create_default_plan_txn_rec
                 (p_budget_version_id   => p_budget_version_id,
                  p_calling_module      => 'CHANGE_MGT',
                  x_return_status       => l_return_status,
                  x_msg_count           => l_msg_count,
                  x_msg_data            => l_msg_data);
Line: 10512

                               pa_debug.g_err_stage := 'Calling  pa_planning_transaction_utils.call_update_rep_lines_api';
Line: 10515

                            pa_planning_transaction_utils.call_update_rep_lines_api
                            (
                               p_source                     => 'PL-SQL'
                              ,p_budget_version_id          => p_budget_version_id
                              ,p_resource_assignment_id_tbl => l_res_assignment_id_tbl
                              ,p_period_name_tbl            => l_period_name_tbl
                              ,p_start_date_tbl             => l_prm_bl_start_date_tbl
                              ,p_end_date_tbl               => l_prm_bl_end_date_tbl
                              ,p_txn_currency_code_tbl      => l_currency_code_tbl
                              ,p_txn_raw_cost_tbl           => l_total_raw_cost_tbl
                              ,p_txn_burdened_cost_tbl      => l_total_burdened_cost_tbl
                              ,p_txn_revenue_tbl            => l_total_revenue_tbl
                              ,p_project_raw_cost_tbl       => l_pc_raw_cost_tbl
                              ,p_project_burdened_cost_tbl  => l_pc_burd_cost_tbl
                              ,p_project_revenue_tbl        => l_pc_revenue_tbl
                              ,p_raw_cost_tbl               => l_pfc_raw_cost_tbl
                              ,p_burdened_cost_tbl          => l_pfc_burd_cost_tbl
                              ,p_revenue_tbl                => l_pfc_revenue_tbl
                              ,p_cost_rejection_code_tbl    => l_cost_rejection_code
                              ,p_revenue_rejection_code_tbl => l_revenue_rejection_code
                              ,p_burden_rejection_code_tbl  => l_burden_rejection_code
                              ,p_other_rejection_code       => l_other_rejection_code
                              ,p_pc_cur_conv_rej_code_tbl   => l_pc_cur_conv_rejection_code
                              ,p_pfc_cur_conv_rej_code_tbl  => l_pfc_cur_conv_rejection_code
                              ,p_quantity_tbl               => l_total_quantity_tbl
                              ,p_rbs_element_id_tbl         => l_pji_prm_rbs_elem_id_tbl
                              ,p_task_id_tbl                => l_pji_prm_task_id_tbl
                              ,p_res_class_code_tbl         => l_pji_prm_res_cls_code_tbl
                              ,p_rate_based_flag_tbl        => l_pji_prm_rbf_tbl
                              ,x_return_status              => x_return_status
                              ,x_msg_count                  => x_msg_count
                              ,x_msg_data                   => x_msg_data);
Line: 10550

                                   pa_debug.g_err_stage := 'pa_planning_transaction_utils.call_update_rep_lines_api errored .... ' || x_msg_data;
Line: 10578

                            SELECT sum(pbl.project_revenue) - l_targ_pc_rev_before_merge
                                  ,sum(pbl.revenue) - l_targ_pfc_rev_before_merge
                            INTO   l_impl_pc_rev_amt
                                  ,l_impl_pfc_rev_amt
                            FROM   pa_budget_lines pbl
                            WHERE  budget_version_id=p_budget_version_id;
Line: 10590

                         p_update_agr_amount_flag => P_update_agreement_amt_flag,
                         p_funding_category       => p_funding_category,
                         p_partial_factor         => l_partial_factor,
                         p_impl_txn_rev_amt       => l_partial_impl_rev_amt,
                         p_impl_pc_rev_amt        => l_impl_pc_rev_amt,
                         p_impl_pfc_rev_amt       => l_impl_pfc_rev_amt,
                         x_msg_data               => l_msg_data,
                         x_msg_count              => l_msg_count,
                         x_return_status          => l_return_status);
Line: 10628

                         l_CI_ID_Tab.delete;
Line: 10647

                         SELECT record_version_number
                         INTO   l_record_version_number
                         FROM   pa_budget_versions
                         WHERE  budget_version_id=p_budget_version_id;
Line: 10817

                    UPDATE pa_fp_merged_ctrl_items
                    SET    impl_proj_func_revenue       =nvl(impl_proj_func_revenue,0)+nvl(l_impl_pfc_revenue,0)
                          ,impl_proj_revenue            =nvl(impl_proj_revenue,0)+nvl(l_impl_pc_revenue,0)
                          ,impl_quantity                =nvl(impl_quantity,0)+nvl(l_rev_ppl_qty,0)
                          ,impl_equipment_quantity      =nvl(impl_equipment_quantity,0)+nvl(l_rev_equip_qty,0)
                          ,impl_agr_revenue             =nvl(impl_agr_revenue,0) + nvl(l_partial_impl_rev_amt,0)
                          ,record_version_number        =record_version_number+1
                          ,last_update_date             =sysdate
                          ,last_update_login            =fnd_global.login_id
                          ,last_updated_by              =fnd_global.user_id
                    WHERE  project_id=l_project_id
                    AND    plan_version_id=p_budget_version_id
                    AND    ci_id=p_ci_id
                    AND    ci_plan_version_id=l_src_ver_id_tbl(j)
                    AND    version_type='REVENUE';
Line: 10845

                    UPDATE pa_budget_versions
                    SET    rev_partially_impl_flag ='N'
                          ,record_version_number   =record_version_number+1
                          ,last_update_date        =sysdate
                          ,last_update_login       =fnd_global.login_id
                          ,last_updated_by         =fnd_global.user_id
                    WHERE  budget_version_id = l_src_ver_id_tbl(j);
Line: 10856

                    UPDATE pa_budget_versions
                    SET    rev_partially_impl_flag ='Y'
                          ,record_version_number   =record_version_number+1
                          ,last_update_date        =sysdate
                          ,last_update_login       =fnd_global.login_id
                          ,last_updated_by         =fnd_global.user_id
                    WHERE  budget_version_id = l_src_ver_id_tbl(j)
                    AND    nvl(rev_partially_impl_flag,'N')='N';
Line: 10872

                 pa_fp_ci_merge.FP_CI_UPDATE_IMPACT
                          (p_ci_id                 => p_ci_id
                          ,p_status_code           => 'CI_IMPACT_IMPLEMENTED'
                          ,p_implemented_by        => FND_GLOBAL.USER_ID
                          ,p_impact_type_code      => l_impact_type_code
                          ,p_commit_flag           => 'N'
                          ,p_init_msg_list         => 'N'
                          ,p_record_version_number => null
                          ,x_return_status         => l_return_status
                          ,x_msg_count             => l_msg_count
                          ,x_msg_data              => l_msg_data
                          );
Line: 10887

                          pa_debug.g_err_stage:= 'Error in FP_CI_UPDATE_IMPACT';
Line: 10968

,p_update_agreement_amt_flag    IN       VARCHAR2
,p_funding_category             IN       VARCHAR2
,x_ci_id_tbl                    OUT      NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
,x_ci_cost_version_id_tbl       OUT      NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
,x_ci_rev_version_id_tbl        OUT      NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
,x_ci_all_version_id_tbl        OUT      NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
,x_budget_version_id_tbl        OUT      NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
,x_fin_plan_type_id_tbl         OUT      NOCOPY SYSTEM.pa_num_tbl_type --File.Sql.39 bug 4440895
,x_fin_plan_type_name_tbl       OUT      NOCOPY SYSTEM.pa_varchar2_150_tbl_type --File.Sql.39 bug 4440895
,x_submit_version_flag_tbl      OUT      NOCOPY SYSTEM.pa_varchar2_1_tbl_type --File.Sql.39 bug 4440895
,x_ci_number                    OUT      NOCOPY SYSTEM.pa_varchar2_100_tbl_type --File.Sql.39 bug 4440895
,x_budget_ci_map_rec_tbl        OUT      NOCOPY budget_ci_map_rec_tbl_type --File.Sql.39 bug 4440895
,x_agreement_id                 OUT      NOCOPY pa_agreements_all.agreement_id%TYPE --File.Sql.39 bug 4440895
,x_funding_category             OUT      NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
,x_return_status                OUT      NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
,x_msg_count                    OUT      NOCOPY NUMBER --File.Sql.39 bug 4440895
,x_msg_data                     OUT      NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
IS
    --Start of variables used for debugging
    l_msg_count                 NUMBER :=0;
Line: 11039

    SELECT 'Y'
    FROM    DUAL
    WHERE   EXISTS (SELECT 1
                    FROM   pa_budget_lines pbl
                    WHERE  pbl.budget_version_id IN (ci_ci_ver_id1, ci_ci_ver_id2)
                    AND(       pbl.cost_rejection_code         IS NOT NULL
                        OR     pbl.revenue_rejection_code      IS NOT NULL
                        OR     pbl.burden_rejection_code       IS NOT NULL
                        OR     pbl.other_rejection_code        IS NOT NULL
                        OR     pbl.pc_cur_conv_rejection_code  IS NOT NULL
                        OR     pbl.pfc_cur_conv_rejection_code IS NOT NULL));
Line: 11355

        SELECT pci.ci_number,
               pct.ci_type_class_code
        INTO   l_ci_number,
               l_ci_type_class_code
        FROM   pa_control_items pci,
               pa_ci_types_b pct
        WHERE  pci.ci_id = p_ci_id_tbl(i)
        AND    pci.ci_type_id=pct.ci_type_id;
Line: 11434

                  SELECT project_id
                  INTO   l_project_id
                  FROM   pa_budget_versions
                  WHERE  budget_version_id=p_budget_version_id_tbl(i);
Line: 11446

                  SELECT (sum(nvl(txn_revenue,0)) )
                  INTO l_total_amount
                  FROM  pa_budget_lines
                  WHERE budget_version_id = NVL(l_ci_all_version_id,l_ci_rev_version_id);
Line: 11636

                    SELECT agreement_id
                    INTO   x_agreement_id
                    FROM   pa_budget_Versions
                    WHERE  budget_Version_id=nvl(l_ci_rev_version_id, l_ci_all_version_id);
Line: 11671

            SELECT fin.name,
                   fin.fin_plan_type_id
            INTO   l_fin_plan_type_name,
                   l_fin_plan_type_id
            FROM   pa_fin_plan_types_vl fin,
                   pa_budget_versions pbv
            WHERE  fin.fin_plan_type_id=pbv.fin_plan_type_id
            AND    pbv.budget_version_id=p_budget_version_id_tbl(i);
Line: 11716

            SELECT budget_status_code,
                   record_version_number,
                   project_id,
                   version_type,
                   plan_processing_code
            INTO   l_budget_status_code,
                   l_record_version_number,
                   l_project_id,
                   l_version_type,
                   l_targ_ver_plan_prc_code -- for Bug 3986129
            FROM   pa_budget_versions pbv
            WHERE  pbv.budget_version_id=p_budget_version_id_tbl(i);
Line: 11998

                          /*SELECT cit.name INTO l_ci_name
                          FROM  pa_control_items pci, pa_ci_types_tl cit
                          WHERE pci.ci_id= x_ci_id_tbl(i)
                          AND  pci.ci_type_id=cit.ci_type_id
                          AND cit.language=userenv('LANG');
Line: 12157

        SELECT agreement_currency_code
        INTO   l_agr_curr_code
        FROM   pa_agreements_all
        WHERE  agreement_id=x_agreement_id;
Line: 12237

 * iii. Insert 2 records into pa_fp_merged_ctrl_items for newly created current working version and the
 *      baselied version with all the attributes of the record stored in the nested tables except the
 *      inclusion_method_code, which would be 'COPIED' for the current working version and 'AUTOMATIC' for the baselined version.
 *  iv. Call is made to pa_fp_ci_merge.FP_CI_UPDATE_IMPACT.
 *--------------------------------------------------------------------------------------------------------*/

PROCEDURE impl_ci_into_autobaseline_proj( p_ci_id                     IN     Pa_control_items.ci_id%TYPE --  The Id of the chg doc that needs to be implemented
                                         ,p_ci_rev_version_id         IN     Pa_budget_versions.budget_version_id%TYPE  DEFAULT  NULL -- The rev budget version id corresponding to the p_ci_id passed. This will be derived internally if not passed
                                         ,p_budget_version_id         IN     Pa_budget_versions.budget_version_id%TYPE -- The Id of the  budget version into which the CO needs to be implemented
                                         ,p_fin_plan_type_id          IN     pa_fin_plan_types_b.fin_plan_type_id%TYPE
                                         ,p_partial_impl_rev_amt      IN     NUMBER    DEFAULT  NULL -- The revenue amount that should be implemented into the target. This will be passed only in the case of partial implementation
                                         ,p_agreement_id              IN     Pa_agreements_all.agreement_id%TYPE  DEFAULT  NULL -- The id of the agreement that is linked with the CO.
                                         ,p_update_agreement_amt_flag IN     VARCHAR2  DEFAULT  NULL -- Indicates whether to  update the agreement amt or not. Null is considered as N
                                         ,p_funding_category          IN     VARCHAR2  DEFAULT  NULL -- The funding category for the agreement
                                         ,x_return_status             OUT    NOCOPY VARCHAR2 -- Indicates the exit status of the API --File.Sql.39 bug 4440895
                                         ,x_msg_data                  OUT    NOCOPY VARCHAR2 -- Indicates the error occurred --File.Sql.39 bug 4440895
                                         ,x_msg_count                 OUT    NOCOPY NUMBER)  -- Indicates the number of error messages --File.Sql.39 bug 4440895
IS
      --Start of variables used for debugging
      l_msg_count                        NUMBER :=0;
Line: 12274

      l_last_update_login_tbl            SYSTEM.PA_NUM_TBL_TYPE  := SYSTEM.PA_NUM_TBL_TYPE();
Line: 12275

      l_last_updated_by_tbl              SYSTEM.PA_NUM_TBL_TYPE  := SYSTEM.PA_NUM_TBL_TYPE();
Line: 12276

      l_last_update_date_tbl             SYSTEM.PA_DATE_TBL_TYPE := SYSTEM.PA_DATE_TBL_TYPE();
Line: 12354

      SELECT
      project_id,
      plan_version_id,
      ci_id,
      ci_plan_version_id,
      record_version_number,
      creation_date,
      created_by,
      last_update_login,
      last_updated_by,
      last_update_date,
      inclusion_method_code,
      included_by_person_id,
      version_type,
      impl_proj_func_raw_cost,
      impl_proj_func_burdened_cost,
      impl_proj_func_revenue,
      impl_proj_raw_cost,
      impl_proj_burdened_cost,
      impl_proj_revenue,
      impl_quantity,
      impl_equipment_quantity,
      impl_agr_revenue
      BULK COLLECT INTO
      l_project_id_tbl,
      l_plan_version_id_tbl,
      l_ci_id_tbl,
      l_ci_plan_ver_id_tbl,
      l_record_ver_number_tbl,
      l_creation_date_tbl,
      l_created_by_tbl,
      l_last_update_login_tbl,
      l_last_updated_by_tbl,
      l_last_update_date_tbl,
      l_incl_method_code_tbl,
      l_incl_by_person_id_tbl,
      l_version_type_tbl,
      l_impl_proj_func_raw_cost_tbl,
      l_impl_proj_func_burd_cost_tbl,
      l_impl_proj_func_revenue_tbl,
      l_impl_proj_raw_cost_tbl,
      l_impl_proj_burd_cost_tbl,
      l_impl_proj_revenue_tbl,
      l_impl_quantity_tbl,
      l_impl_equipment_quant_tbl,
      l_impl_agr_revenue_tbl
      FROM   pa_fp_merged_ctrl_items
      WHERE  plan_version_id = p_budget_version_id;
Line: 12452

      SELECT Nvl(pbv.labor_quantity, 0),
             Nvl(pbv.equipment_quantity, 0),
             Nvl(pbv.revenue, 0),
             Nvl(pbv.total_project_revenue, 0),
             pbv.project_id,
             p.project_currency_code,
             p.projfunc_currency_code
      INTO   l_rev_ppl_quantity_bf_mg,
             l_rev_equip_quantity_bf_mg,
             l_impl_pfc_revenue_bf_mg,
             l_impl_pc_revenue_bf_mg,
             l_project_id,
             l_project_currency_code,
             l_projfunc_currency_code
      FROM   pa_budget_versions pbv,
             pa_projects_all p
      WHERE  pbv.project_id = p.project_id
      AND    pbv.budget_version_id = p_budget_version_id;
Line: 12478

      SELECT nvl(sum(txn_revenue),0) total_amt
            ,nvl(sum(revenue),0)  total_amt_in_pfc
            ,nvl(sum(project_revenue),0) total_amt_in_pc
      INTO   l_total_amount,
             l_total_amount_in_pfc,
             l_total_amount_in_pc
      FROM   pa_budget_lines
      WHERE  budget_version_id = p_ci_rev_version_id;
Line: 12541

                         p_update_agr_amount_flag => P_update_agreement_amt_flag,
                         p_funding_category       => p_funding_category,
                         p_partial_factor         => l_partial_factor,
                         p_impl_txn_rev_amt       => l_partial_impl_rev_amt,
                         p_impl_pc_rev_amt        => l_impl_pc_rev_amt,
                         p_impl_pfc_rev_amt       => l_impl_pfc_rev_amt,
                         x_msg_data               => l_msg_data,
                         x_msg_count              => l_msg_count,
                         x_return_status          => l_return_status);
Line: 12569

      l_CI_ID_Tab.delete;
Line: 12648

                  pa_debug.g_err_stage:= 'Inserting into pa_fp_merged_ctrl_items with old data';
Line: 12653

                  INSERT  INTO pa_fp_merged_ctrl_items
                          (project_id,
                          plan_version_id,
                          ci_id,
                          ci_plan_version_id,
                          record_version_number,
                          creation_date,
                          created_by,
                          last_update_login,
                          last_updated_by,
                          last_update_date,
                          inclusion_method_code,
                          included_by_person_id,
                          version_type,
                          impl_proj_func_raw_cost,
                          impl_proj_func_burdened_cost,
                          impl_proj_func_revenue,
                          impl_proj_raw_cost,
                          impl_proj_burdened_cost,
                          impl_proj_revenue,
                          impl_quantity,
                          impl_equipment_quantity,
                          impl_agr_revenue)
                  VALUES (l_project_id_tbl(i),
                          l_new_cw_version_id, -- The new current working version id
                          l_ci_id_tbl(i),
                          l_ci_plan_ver_id_tbl(i),
                          1, -- Bug 3877815: Review comment
                          l_creation_date_tbl(i),
                          l_created_by_tbl(i),
                          FND_GLOBAL.login_id,
                          FND_GLOBAL.user_id,
                          SYSDATE,
                          l_incl_method_code_tbl(i),
                          l_incl_by_person_id_tbl(i),
                          l_version_type_tbl(i),
                          l_impl_proj_func_raw_cost_tbl(i),
                          l_impl_proj_func_burd_cost_tbl(i),
                          l_impl_proj_func_revenue_tbl(i),
                          l_impl_proj_raw_cost_tbl(i),
                          l_impl_proj_burd_cost_tbl(i),
                          l_impl_proj_revenue_tbl(i),
                          l_impl_quantity_tbl(i),
                          l_impl_equipment_quant_tbl(i),
                          l_impl_agr_revenue_tbl(i));
Line: 12702

                  INSERT  INTO pa_fp_merged_ctrl_items
                          (project_id,
                          plan_version_id,
                          ci_id,
                          ci_plan_version_id,
                          record_version_number,
                          creation_date,
                          created_by,
                          last_update_login,
                          last_updated_by,
                          last_update_date,
                          inclusion_method_code,
                          included_by_person_id,
                          version_type,
                          impl_proj_func_raw_cost,
                          impl_proj_func_burdened_cost,
                          impl_proj_func_revenue,
                          impl_proj_raw_cost,
                          impl_proj_burdened_cost,
                          impl_proj_revenue,
                          impl_quantity,
                          impl_equipment_quantity,
                          impl_agr_revenue)
                  VALUES (l_project_id_tbl(i),
                          l_baseline_version_id, -- The baseline version id
                          l_ci_id_tbl(i),
                          l_ci_plan_ver_id_tbl(i),
                          1,
                          SYSDATE,
                          FND_GLOBAL.user_id,
                          FND_GLOBAL.login_id,
                          FND_GLOBAL.user_id,
                          SYSDATE,
                          'AUTOMATIC', -- Bug 3877815: Review comment
                          l_incl_by_person_id_tbl(i),
                          l_version_type_tbl(i),
                          l_impl_proj_func_raw_cost_tbl(i),
                          l_impl_proj_func_burd_cost_tbl(i),
                          l_impl_proj_func_revenue_tbl(i),
                          l_impl_proj_raw_cost_tbl(i),
                          l_impl_proj_burd_cost_tbl(i),
                          l_impl_proj_revenue_tbl(i),
                          l_impl_quantity_tbl(i),
                          l_impl_equipment_quant_tbl(i),
                          l_impl_agr_revenue_tbl(i));
Line: 12759

      SELECT Nvl(labor_quantity, 0),
             Nvl(equipment_quantity, 0),
             Nvl(revenue, 0),
             Nvl(total_project_revenue, 0),
             Nvl(rev_partially_impl_flag, 'N')
      INTO   l_rev_ppl_quantity_af_mg,
             l_rev_equip_quantity_af_mg,
             l_impl_pfc_revenue_af_mg,
             l_impl_pc_revenue_af_mg,
             l_final_rev_par_impl_flag
      FROM   pa_budget_versions
      WHERE  project_id = l_project_id
      AND    budget_version_id = l_new_cw_version_id;
Line: 12792

            UPDATE pa_fp_merged_ctrl_items
            SET    impl_proj_func_revenue  = (Nvl(impl_proj_func_revenue,0) + l_impl_pfc_revenue),
                   impl_proj_revenue       = (Nvl(impl_proj_revenue,0) + l_impl_pc_revenue),
                   impl_quantity           = (Nvl(impl_quantity,0) + l_rev_ppl_quantity),
                   impl_equipment_quantity = (Nvl(impl_equipment_quantity,0) + l_rev_equip_quantity),
                   impl_agr_revenue        = (Nvl(l_implemented_amt,0) + Nvl(l_partial_impl_rev_amt,0)),
                   record_version_number   = (Nvl(record_version_number, 0) + 1),
                   last_update_login       = FND_GLOBAL.login_id,
                   last_updated_by         = FND_GLOBAL.user_id,
                   last_update_date        = SYSDATE
            WHERE  project_id = l_project_id
            AND    ci_id = p_ci_id
            AND    plan_version_id = l_new_cw_version_id
            AND    version_type = 'REVENUE';
Line: 12808

            UPDATE pa_fp_merged_ctrl_items
            SET    impl_proj_func_revenue  = (Nvl(impl_proj_func_revenue,0) + l_impl_pfc_revenue),
                   impl_proj_revenue       = (Nvl(impl_proj_revenue,0) + l_impl_pc_revenue),
                   impl_quantity           = (Nvl(impl_quantity,0) + l_rev_ppl_quantity),
                   impl_equipment_quantity = (Nvl(impl_equipment_quantity,0) + l_rev_equip_quantity),
                   impl_agr_revenue        = (Nvl(l_implemented_amt,0) + Nvl(l_partial_impl_rev_amt,0)),
                   record_version_number   = (Nvl(record_version_number, 0) + 1),
                   last_update_login       = FND_GLOBAL.login_id,
                   last_updated_by         = FND_GLOBAL.user_id,
                   last_update_date        = SYSDATE
            WHERE  project_id = l_project_id
            AND    ci_id = p_ci_id
            AND    plan_version_id = l_baseline_version_id
            AND    version_type = 'REVENUE';
Line: 12906

            pa_debug.g_err_stage:= 'Calling pa_fp_ci_merge.FP_CI_UPDATE_IMPACT';
Line: 12910

      pa_fp_ci_merge.FP_CI_UPDATE_IMPACT
                        (p_ci_id                 => p_ci_id
                        ,p_status_code           => 'CI_IMPACT_IMPLEMENTED'
                        ,p_implemented_by        => FND_GLOBAL.USER_ID
                        ,p_impact_type_code      => 'FINPLAN_REVENUE'
                        ,p_commit_flag           => 'N'
                        ,p_init_msg_list         => 'N'
                        ,p_record_version_number => null
                        ,x_return_status         => l_return_status
                        ,x_msg_count             => l_msg_count
                        ,x_msg_data              => l_msg_data);
Line: 12924

                                 pa_debug.g_err_stage:= 'Error in FP_CI_UPDATE_IMPACT';
Line: 12930

            pa_debug.g_err_stage:= 'Call to pa_fp_ci_merge.FP_CI_UPDATE_IMPACT done';
Line: 12949

           UPDATE pa_budget_versions
           SET    rev_partially_impl_flag ='N'
                 ,record_version_number   = record_version_number+1
                 ,last_update_date        = sysdate
                 ,last_update_login       = fnd_global.login_id
                 ,last_updated_by         = fnd_global.user_id
           WHERE  budget_version_id       = p_ci_rev_version_id;
Line: 12967

               UPDATE pa_budget_versions
               SET    rev_partially_impl_flag ='Y'
                     ,record_version_number   = record_version_number+1
                     ,last_update_date        = sysdate
                     ,last_update_login       = fnd_global.login_id
                     ,last_updated_by         = fnd_global.user_id
               WHERE  budget_version_id       = p_ci_rev_version_id;
Line: 13071

 ,p_update_agreement_amt_flag       IN     VARCHAR2
 ,p_funding_category                IN     VARCHAR2
 ,p_raTxn_rollup_api_call_flag      IN     VARCHAR2   --IPM Arch Enhancement Bug 4865563
 ,p_add_msg_to_stack                IN     VARCHAR2
 ,x_translated_msgs_tbl             OUT    NOCOPY SYSTEM.pa_varchar2_2000_tbl_type --File.Sql.39 bug 4440895
 ,x_translated_err_msg_count        OUT    NOCOPY NUMBER --File.Sql.39 bug 4440895
 ,x_translated_err_msg_level_tbl    OUT    NOCOPY SYSTEM.pa_varchar2_30_tbl_type --File.Sql.39 bug 4440895
 ,x_return_status                   OUT    NOCOPY VARCHAR2 --File.Sql.39 bug 4440895
 ,x_msg_count                       OUT    NOCOPY NUMBER --File.Sql.39 bug 4440895
 ,x_msg_data                        OUT    NOCOPY VARCHAR2) --File.Sql.39 bug 4440895
IS
    --Start of variables used for debugging
    l_msg_count                     NUMBER :=0;
Line: 13211

    ,p_update_agreement_amt_flag     => p_update_agreement_amt_flag
    ,p_funding_category              => p_funding_category
    ,x_ci_id_tbl                     => l_ci_id_tbl
    ,x_ci_cost_version_id_tbl        => l_ci_cost_version_id_tbl
    ,x_ci_rev_version_id_tbl         => l_ci_rev_version_id_tbl
    ,x_ci_all_version_id_tbl         => l_ci_all_version_id_tbl
    ,x_ci_number                     => l_ci_number
    ,x_budget_version_id_tbl         => l_budget_version_id_tbl
    ,x_fin_plan_type_id_tbl          => l_fin_plan_type_id_tbl
    ,x_fin_plan_type_name_tbl        => l_fin_plan_type_name_tbl
    ,x_submit_version_flag_tbl       => l_submit_version_flag_tbl
    ,x_budget_ci_map_rec_tbl         => l_budget_ci_map_rec_tbl
    ,x_agreement_id                  => l_agreement_id
    ,x_funding_category              => l_funding_category
    ,x_return_status                 => x_return_status
    ,x_msg_count                     => x_msg_count
    ,x_msg_data                      => x_msg_data );
Line: 13371

                         SELECT Nvl(bv.approved_cost_plan_type_flag, 'N'),
                                Nvl(bv.approved_rev_plan_type_flag, 'N'),
                                Nvl(pj.baseline_funding_flag, 'N')
                         INTO   l_targ_app_cost_flag,
                                l_targ_app_rev_flag,
                                l_baseline_funding_flag
                         FROM   pa_projects_all pj,
                                pa_budget_versions bv
                         WHERE  bv.budget_version_id = l_budget_version_id_tbl(j)
                         AND    bv.project_id = pj.project_id;
Line: 13411

                                                           ,p_update_agreement_amt_flag => p_update_agreement_amt_flag
                                                           ,p_funding_category          => l_funding_category
                                                           ,x_return_status             => x_return_status
                                                           ,x_msg_data                  => x_msg_data
                                                           ,x_msg_count                 => x_msg_count);
Line: 13459

                              ,p_update_agreement_amt_flag    => p_update_agreement_amt_flag
                              ,p_funding_category             => l_funding_category
                              ,p_raTxn_rollup_api_call_flag   => p_raTxn_rollup_api_call_flag  --IPM Arch Enhancement Bug 4865563
                              ,x_return_status                => x_return_status
                              ,x_msg_data                     => x_msg_data
                              ,x_msg_count                    => x_msg_count);