DBA Data[Home] [Help]

APPS.PA_ORG_UTILS SQL Statements

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

Line: 26

       SELECT  max(level)
        INTO  l_tmp_level
         FROM    per_org_structure_elements
        WHERE    org_structure_version_id =  p_org_version_id
        AND     organization_id_parent =  p_child_parent_org_id
        CONNECT BY PRIOR organization_id_child = organization_id_parent
        AND  org_structure_version_id = p_org_version_id
        START WITH organization_id_parent = p_start_org_id
        AND   org_structure_version_id = p_org_version_id;
Line: 38

           SELECT  max(level)
            INTO l_tmp_level
           FROM    per_org_structure_elements
           WHERE    org_structure_version_id =  p_org_version_id
            AND     organization_id_child =  p_child_parent_org_id
            CONNECT BY PRIOR organization_id_child = organization_id_parent
            AND  org_structure_version_id = p_org_version_id
            START WITH organization_id_parent = p_start_org_id
            AND   org_structure_version_id = p_org_version_id;
Line: 63

select parent_level  into l_org_level
from pa_org_hierarchy_denorm
where org_hierarchy_version_id = p_org_version_id
and child_organization_id =  p_child_parent_org_id
and parent_organization_id = p_child_parent_org_id
and pa_org_use_type = 'TP_SCHEDULE';
Line: 82

        SELECT  max(level) into l_max_org_level
        FROM  per_org_structure_elements
        WHERE  org_structure_version_id = p_org_version_id
        CONNECT BY PRIOR  organization_id_child =  organization_id_parent
               and org_structure_version_id = p_org_version_id
        START WITH  organization_id_parent = p_start_org_id
               and org_structure_version_id = p_org_version_id;
Line: 101

        SELECT a.organization_id_parent
        INTO   l_start_org_id
        FROM per_org_structure_elements a
        WHERE org_structure_version_id = p_org_version_id
        AND   not exists ( select 'a' from per_org_structure_elements  b
        WHERE a.organization_id_parent = b.organization_id_child and
        a.org_structure_version_id = b.org_structure_version_id)
        AND rownum = 1;
Line: 119

   select decode(x_usage,'PROJECTS',PROJ_ORG_STRUCTURE_VERSION_ID
                 ,'EXPENDITURES',EXP_ORG_STRUCTURE_VERSION_ID
                 ,'REPORTING',ORG_STRUCTURE_VERSION_ID)
   into x_org_version_id
   from pa_implementations;
Line: 133

   select decode(x_usage,'PROJECTS',PROJ_ORG_STRUCTURE_VERSION_ID
                 ,'EXPENDITURES',EXP_ORG_STRUCTURE_VERSION_ID
                 ,'REPORTING',ORG_STRUCTURE_VERSION_ID
                 ,'BURDENING',to_number(org_information2))
   into x_org_version_id
   from pa_implementations imp,hr_organization_information hr
   where imp.business_group_id = hr.organization_id
     and hr.org_information_context = 'Project Burdening Hierarchy';
Line: 150

   select decode(x_usage,'PROJECTS',PROJ_START_ORG_ID
                 ,'EXPENDITURES',EXP_START_ORG_ID
                 ,'REPORTING',START_ORGANIZATION_ID)
   into x_start_org_id
   from pa_implementations;
Line: 165

   select decode(x_usage,'PROJECTS',PROJ_START_ORG_ID
                 ,'EXPENDITURES',EXP_START_ORG_ID
                 ,'REPORTING',START_ORGANIZATION_ID)
   into x_start_org_id
   from pa_implementations;
Line: 171

    select distinct organization_id_parent into x_start_org_id
    from per_org_structure_elements a
         ,pa_implementations b
         ,hr_organization_information c
         where organization_id_parent not in
          ( select d.ORGANIZATION_ID_CHILD from per_org_structure_elements d
            where d.org_structure_version_id = to_number(c.org_information2)
          )
         and a.org_structure_version_id = to_number(c.org_information2)
         and b.business_group_id = c.organization_id
         and c.org_information_context = 'Project Burdening Hierarchy' ;
Line: 209

     SELECT l_new_start_org_id
       FROM dual
     UNION ALL
     SELECT organization_id_child
       FROM per_org_structure_elements
      WHERE org_structure_version_id = l_new_org_version_id
    CONNECT BY PRIOR organization_id_child = organization_id_parent
        AND org_structure_version_id = l_new_org_version_id
 START WITH organization_id_parent = l_new_start_org_id
        AND org_structure_version_id = l_new_org_version_id;
Line: 223

     SELECT l_org_id
       FROM dual
     UNION ALL
     SELECT organization_id_child
       FROM per_org_structure_elements
      WHERE org_structure_version_id = l_new_org_version_id
 CONNECT BY PRIOR organization_id_child = organization_id_parent
        AND org_structure_version_id = l_new_org_version_id
 START WITH organization_id_parent = l_org_id
        AND org_structure_version_id = l_new_org_version_id;
Line: 237

  (select se.organization_id_child
  from per_org_structure_elements se
  where se.org_structure_version_id = l_old_org_version_id
  connect by prior se.organization_id_child = se.organization_id_parent
  and org_structure_version_id = l_old_org_version_id
  start with se.organization_id_parent = l_old_org_start_id
  and org_structure_version_id = l_old_org_version_id
   union
  select l_old_org_start_id from sys.dual)
   intersect
  (select l_new_start_org_id from sys.dual );
Line: 255

	SELECT 'Y' FROM pa_implementations_all
	WHERE ( proj_org_structure_version_id = c_org_struct_version_id
	OR exp_org_structure_version_id =  c_org_struct_version_id )
	and ORG_ID <> l_org_id;
Line: 291

    insert into pa_all_organizations
    (organization_id,
     org_id,
     pa_org_use_type )
     ( (select se.organization_id_child
               ,x_org_id
               ,'PROJECTS'
        from per_org_structure_elements se
        where  org_structure_version_id =  x_new_proj_org_version_id
        AND     EXISTS (select 'X'
                        from hr_organization_information info
                        where info.organization_id = se.organization_id_child
                        and   info.org_information1 = 'PA_PROJECT_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y')
        connect by prior se.organization_id_child =
                se.organization_id_parent
        and org_structure_version_id = x_new_proj_org_version_id
        start with se.organization_id_parent = x_new_proj_start_org_id
        and org_structure_version_id = x_new_proj_org_version_id
           union
        select x_new_proj_start_org_id
               ,x_org_id
               ,'PROJECTS'
        from    sys.duaL   /* Exists clause added for bug#2591146 */
        where   EXISTS (select 'X'
                        from hr_organization_information info
                        where info.organization_id = x_new_proj_start_org_id
                        and   info.org_information1 = 'PA_PROJECT_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y')
       )
           minus
       (select organization_id,
               org_id,
               pa_org_use_type
        from pa_all_organizations
        where pa_org_use_type = 'PROJECTS'
        and  org_id = x_org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
       )
      );
Line: 335

     delete from pa_cc_tp_schedule_line_lkp;
Line: 366

                         select 'YES' into proj_org_true
                           from hr_organization_information
                          where organization_id = l_child_org_id
                            and ORG_INFORMATION_CONTEXT = 'CLASS'
                            and ORG_INFORMATION1 = 'PA_PROJECT_ORG'
                            and ORG_INFORMATION2 = 'Y';
Line: 401

    insert into pa_all_organizations
    (organization_id,
     org_id,
     pa_org_use_type)
     ( (select se.organization_id_child
               ,x_org_id
               ,'EXPENDITURES'
        from per_org_structure_elements se
        where  org_structure_version_id =  x_new_exp_org_version_id
        AND     EXISTS (select 'X'
                        from hr_organization_information info
                        where info.organization_id = se.organization_id_child
                        and   info.org_information1 = 'PA_EXPENDITURE_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y')
        connect by prior se.organization_id_child =
                se.organization_id_parent
        and org_structure_version_id = x_new_exp_org_version_id
        start with se.organization_id_parent = x_new_exp_start_org_id
        and org_structure_version_id = x_new_exp_org_version_id
           union
        select x_new_exp_start_org_id
               ,x_org_id
               ,'EXPENDITURES'
        from    sys.duaL  /* Exists clause added for bug#2591146 */
        where   EXISTS (select 'X'
                        from  hr_organization_information info
                        where info.organization_id = x_new_exp_start_org_id
                        and   info.org_information1 = 'PA_EXPENDITURE_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y')
       )
           minus
       (select organization_id,
               org_id,
               pa_org_use_type
        from pa_all_organizations
        where pa_org_use_type = 'EXPENDITURES'
        and  org_id = x_org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
       )
      );
Line: 474

                         select 'YES' into exp_org_true
                           from hr_organization_information
                          where organization_id = l_child_org_id
                            and ORG_INFORMATION_CONTEXT = 'CLASS'
                            and ORG_INFORMATION1 = 'PA_EXPENDITURE_ORG'
                            and ORG_INFORMATION2 = 'Y';
Line: 594

     SELECT l_dummy_level,lp_start_org_id
       FROM dual
     UNION ALL
     SELECT level,organization_id_child
       FROM per_org_structure_elements
      WHERE org_structure_version_id = lp_org_version_id
    CONNECT BY PRIOR organization_id_child = organization_id_parent
        AND org_structure_version_id = lp_org_version_id
 START WITH organization_id_parent = lp_start_org_id
        AND org_structure_version_id = lp_org_version_id;
Line: 607

     SELECT l_dummy_level,lp_org_id
       FROM dual
     UNION ALL
     SELECT level,organization_id_child
       FROM per_org_structure_elements
      WHERE org_structure_version_id = lp_org_version_id
 CONNECT BY PRIOR organization_id_child = organization_id_parent
        AND org_structure_version_id = lp_org_version_id
 START WITH organization_id_parent = lp_org_id
        AND org_structure_version_id = lp_org_version_id;
Line: 621

SELECT 'x'
FROM   dual
WHERE not exists
  ( SELECT 'x' from pa_org_hierarchy_denorm
    WHERE  org_hierarchy_version_id = nvl(lp_org_version_id,org_hierarchy_version_id)
    and    pa_org_use_type = 'TP_SCHEDULE' );
Line: 668

          DELETE from pa_org_hierarchy_denorm
          WHERE org_hierarchy_version_id = p_org_version_id
           AND pa_org_use_type = 'TP_SCHEDULE';
Line: 762

  select se.organization_id_parent
  from per_org_structure_elements se
  where se.org_structure_version_id = x_org_version_id
  connect by prior se.organization_id_parent =
                             se.organization_id_child
  and org_structure_version_id = x_org_version_id
  start with se.organization_id_child =
                       x_organization_id_parent
  and org_structure_version_id = x_org_version_id
  union
  select x_organization_id_parent from sys.dual
   )
  intersect
  (
  select v_start_org_id from sys.dual
  );
Line: 781

  (select se.organization_id_child
  from per_org_structure_elements se
  where se.org_structure_version_id =
   x_org_version_id
  connect by prior se.organization_id_child =
            se.organization_id_parent
  and org_structure_version_id = x_org_version_id
  start with se.organization_id_parent =
        v_start_org_id
  and org_structure_version_id = x_org_version_id
      union
  select v_start_org_id
  from sys.dual)
   intersect
  (select x_organization_id_parent
  from sys.dual );
Line: 801

 (SELECT x_organization_id_parent
       FROM dual
     UNION
     SELECT organization_id_parent
       FROM per_org_structure_elements
      WHERE org_structure_version_id = x_org_version_id
 CONNECT BY PRIOR organization_id_parent= organization_id_child
        AND org_structure_version_id = x_org_version_id
 START WITH organization_id_child = x_organization_id_parent
        AND org_structure_version_id = x_org_version_id)    /* Bug#2643047, Added this condition as we have to query only for this org_structure_version_id */
 union ALL
 (SELECT x_organization_id_child from dual);
Line: 820

 (SELECT lp_organization_id_parent
       FROM dual
     UNION
     SELECT organization_id_parent
       FROM per_org_structure_elements
      WHERE org_structure_version_id = lp_org_version_id
 CONNECT BY PRIOR organization_id_parent= organization_id_child
        AND org_structure_version_id = lp_org_version_id
 START WITH organization_id_child = lp_organization_id_parent
        AND org_structure_version_id = lp_org_version_id)
 union ALL
 (SELECT lp_organization_id_child from dual);
Line: 850

  for imp_rec in ( select org_id,proj_start_org_id
                   from   pa_implementations_all imp
                   where  proj_org_structure_version_id = x_org_version_id
                  )

  loop

   /*Bug# 2247737*/
    l_process_schedule_hier := 'Y';
Line: 883

      insert into pa_all_organizations
        (organization_id,
         org_id,
         pa_org_use_type)
      (select
         x_organization_id_child,
         imp_rec.org_id,
         'PROJECTS'
       from sys.dual
       where exists (select 'x'
            from hr_organization_information info
            where info.organization_id = x_organization_id_child
            and   info.org_information1 = 'PA_PROJECT_ORG'
            and   info.org_information_context||'' = 'CLASS'
            and   info.org_information2 = 'Y')
       and   not exists
             (select 'X'
              from pa_all_organizations
              where organization_id = x_organization_id_child
              and  org_id = imp_rec.org_id  --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
            and   pa_org_use_type = 'PROJECTS')
       ) ;
Line: 908

       Update pa_all_organizations
        set   inactive_date   = NULL
        where organization_id = x_organization_id_child
        and   org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
        and   pa_org_use_type = 'PROJECTS'
        and  exists (select 'x'                          -- EXISTS condition added for bug 2890516
            from hr_organization_information info
            where info.organization_id = x_organization_id_child
            and   info.org_information1 = 'PA_PROJECT_ORG'
            and   info.org_information_context||'' = 'CLASS'
            and   info.org_information2 = 'Y');
Line: 923

     delete from pa_cc_tp_schedule_line_lkp;
Line: 932

    select 'Y' into l_proj_org_true
      from hr_organization_information info
            where info.organization_id = x_organization_id_child
            and   info.org_information1 = 'PA_PROJECT_ORG'
            and   info.org_information_context||'' = 'CLASS'
            and   info.org_information2 = 'Y';
Line: 961

  for imp_rec in ( select org_id, exp_start_org_id
                   from   pa_implementations_all imp
                   where  exp_org_structure_version_id = x_org_version_id
                  )
  loop

  /*Bug# 2247737*/

    l_process_schedule_hier := 'Y';
Line: 995

      insert into pa_all_organizations
        (organization_id,
         org_id,
         pa_org_use_type)
      (select
         x_organization_id_child,
         imp_rec.org_id,
         'EXPENDITURES'
       from sys.dual
       where exists (select 'x'
            from hr_organization_information info
            where info.organization_id = x_organization_id_child
            and   info.org_information1 = 'PA_EXPENDITURE_ORG'
            and   info.org_information_context||'' = 'CLASS'
            and   info.org_information2 = 'Y')
       and not exists
             (select 'X'
              from pa_all_organizations
              where organization_id = x_organization_id_child
              and  org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
              and   pa_org_use_type = 'EXPENDITURES')
        ) ;
Line: 1020

       Update pa_all_organizations
        set inactive_date=NULL
        where organization_id =x_organization_id_child
        and   org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
        and   pa_org_use_type = 'EXPENDITURES'
        and  exists (select 'x'                          -- EXISTS condition added for bug 2890516
            from hr_organization_information info
            where info.organization_id = x_organization_id_child
            and   info.org_information1 = 'PA_EXPENDITURE_ORG'
            and   info.org_information_context||'' = 'CLASS'
            and   info.org_information2 = 'Y');
Line: 1041

    select 'Y' into l_exp_org_true
      from hr_organization_information info
            where info.organization_id = x_organization_id_child
            and   info.org_information1 = 'PA_EXPENDITURE_ORG'
            and   info.org_information_context||'' = 'CLASS'
            and   info.org_information2 = 'Y';
Line: 1144

     SELECT child_organization_id
       from pa_org_hierarchy_denorm
      where org_hierarchy_version_id = x_org_version_id
        and parent_organization_id = x_organization_id_child;
Line: 1154

  for imp_rec in ( select org_id,proj_start_org_id
                   from   pa_implementations_all imp
                   where  proj_org_structure_version_id = x_org_version_id
                  )

  loop
      update pa_all_organizations
      set inactive_date = trunc(sysdate)
      where organization_id = x_organization_id_child
      and  org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
      and   pa_org_use_type = 'PROJECTS'
      and inactive_date is null ; -- Bug Ref # 6367868
Line: 1171

  for imp_rec in ( select org_id, exp_start_org_id
                   from   pa_implementations_all imp
                   where  exp_org_structure_version_id = x_org_version_id
                  )
  loop
      update pa_all_organizations
      set inactive_date = trunc(sysdate)
      where organization_id = x_organization_id_child
      and  org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
      and   pa_org_use_type = 'EXPENDITURES'
      and inactive_date is null ; -- Bug Ref # 6367868
Line: 1185

     delete from pa_cc_tp_schedule_line_lkp;
Line: 1191

      delete from pa_org_hierarchy_denorm
            where org_hierarchy_version_id = x_org_version_id
              and (child_organization_id = l_parent_org_id
               or parent_organization_id = l_parent_org_id);
Line: 1246

   select se.organization_id_parent
   from   per_org_structure_elements se
   where  se.org_structure_version_id = v_org_structure_version_id
          and     se.organization_id_parent =
                                v_start_org_id
          connect by prior se.organization_id_parent =
	                        se.organization_id_child
          and org_structure_version_id = v_org_structure_version_id
          start with se.organization_id_child =
                                x_organization_id
          and org_structure_version_id = v_org_structure_version_id
  );
Line: 1261

                (select    se.organization_id_child
                 from      per_org_structure_elements se
                 where     se.org_structure_version_id = v_org_structure_version_id
                   and     se.organization_id_child = x_organization_id ---made changes as Suggested
                 connect by prior se.organization_id_child =
                      se.organization_id_parent
                        and org_structure_version_id = v_org_structure_version_id
                      start with se.organization_id_parent =
                      v_start_org_id
                      and org_structure_version_id = v_org_structure_version_id );
Line: 1275

 (SELECT x_organization_id
       FROM dual
     UNION ALL
     SELECT organization_id_parent
       FROM per_org_structure_elements
      WHERE org_structure_version_id = v_org_structure_version_id
 CONNECT BY PRIOR organization_id_parent= organization_id_child
        AND org_structure_version_id = v_org_structure_version_id
 START WITH organization_id_child = x_organization_id);
Line: 1289

     delete from pa_cc_tp_schedule_line_lkp;
Line: 1301

          for imp_rec  in (select   proj_start_org_id, proj_org_structure_version_id,
                                    org_id
                           from     pa_implementations_all )
          loop
             v_start_org_id := imp_rec.proj_start_org_id;
Line: 1314

                        insert into pa_all_organizations
                        (organization_id,
                         org_id,
                         pa_org_use_type)
                                (select x_organization_id,
                         imp_rec.org_id, 'PROJECTS'
                         from   sys.dual
                         where  not exists ( select    'X'
                         from      pa_all_organizations
                         where     organization_id = x_organization_id
                         and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                         and       pa_org_use_type = 'PROJECTS' ));
Line: 1327

                        if sql%rowcount = 0 then --- Means Row was not inserted as it was there
                                           ---- Earlier, IN This case set inactive_date to
                                           ---  NULL.
                           update    pa_all_organizations
                           set       inactive_date = null
                           where     organization_id = x_organization_id
                           and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                           and       pa_org_use_type = 'PROJECTS' ;
Line: 1356

                   insert into pa_all_organizations
                        (organization_id,
                         org_id,
                         pa_org_use_type)
                        (select x_organization_id,
                         imp_rec.org_id, 'PROJECTS'
                        from   sys.dual
                                where  not exists ( select    'X'
                                      from      pa_all_organizations
                                      where     organization_id = x_organization_id
                                      and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                                      and       pa_org_use_type = 'PROJECTS' ));
Line: 1368

                        if sql%rowcount = 0 then --- Means Row was not inserted as it was there
                                           ---- Earlier, IN This case set inactive_date to
                                           ---  NULL.
                           update    pa_all_organizations
                           set       inactive_date = null
                           where     organization_id = x_organization_id
                           and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                           and       pa_org_use_type = 'PROJECTS' ;
Line: 1389

          for imp_rec  in (select   proj_start_org_id, proj_org_structure_version_id,
                                    org_id
                           from     pa_implementations_all )
          loop

                      update    pa_all_organizations
                      set       inactive_date = trunc(sysdate)
                      where     organization_id = x_organization_id
                      and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                      and       pa_org_use_type = 'PROJECTS'
		      and       inactive_date is null; -- Bug Ref # 6367868
Line: 1401

                     delete from pa_org_hierarchy_denorm
                     where child_organization_id = x_organization_id
                       and org_hierarchy_version_id = imp_rec.proj_org_structure_version_id
		       and pa_org_use_type = 'PROJECTS';  /* Bug#2643047 - Only PROJECTS records need to be deleted as we are checking
Line: 1422

          for imp_rec  in (select   exp_start_org_id, exp_org_structure_version_id,
                                    org_id
                           from     pa_implementations_all )
          loop
             v_start_org_id := imp_rec.exp_start_org_id;
Line: 1435

                         insert into pa_all_organizations
                                        (organization_id,
                                         org_id,
                                         pa_org_use_type)
                                         (select x_organization_id,
                                          imp_rec.org_id, 'EXPENDITURES'
                                          from   sys.dual
                                  where  not exists ( select    'X'
                                      from      pa_all_organizations
                                      where     organization_id = x_organization_id
                                      and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                                      and       pa_org_use_type = 'EXPENDITURES' ));
Line: 1448

                        if sql%rowcount = 0 then --- Means Row was not inserted as it was there
                                           ---- Earlier, IN This case set inactive_date to
                                           ---  NULL.
                                update    pa_all_organizations
                                set       inactive_date = null
                                where     organization_id = x_organization_id
                                and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                                and       pa_org_use_type = 'EXPENDITURES' ;
Line: 1476

                   insert into pa_all_organizations
                        (organization_id,
                         org_id,
                         pa_org_use_type)
                        (select x_organization_id,
                         imp_rec.org_id, 'EXPENDITURES'
                        from   sys.dual
                                where  not exists ( select    'X'
                                      from      pa_all_organizations
                                      where     organization_id = x_organization_id
                                      and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                                      and       pa_org_use_type = 'EXPENDITURES' ));
Line: 1488

                        if sql%rowcount = 0 then --- Means Row was not inserted as it was there
                                           ---- Earlier, IN This case set inactive_date to
                                           ---  NULL.
                           update    pa_all_organizations
                           set       inactive_date = null
                           where     organization_id = x_organization_id
                           and       org_id = imp_rec.org_id--MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                           and       pa_org_use_type = 'EXPENDITURES' ;
Line: 1509

          for imp_rec  in (select   exp_start_org_id, exp_org_structure_version_id,
                                    org_id
                           from     pa_implementations_all )
          loop

                      update    pa_all_organizations
                      set       inactive_date = trunc(sysdate)
                      where     organization_id = x_organization_id
                      and       org_id = imp_rec.org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
                      and       pa_org_use_type = 'EXPENDITURES'
		      and       inactive_date is null ; -- Bug Ref # 6367868
Line: 1521

                     delete from pa_org_hierarchy_denorm
                     where child_organization_id = x_organization_id
                       and org_hierarchy_version_id = imp_rec.exp_org_structure_version_id
		        and pa_org_use_type = 'EXPENDITURES'; /* Bug#2643047 -  Only EXPENDITURES records need to be deleted as we
Line: 1551

        SELECT  se.organization_id_child organization_id
                FROM    per_org_structure_elements se
                WHERE   org_structure_version_id =  x_old_org_version_id
                CONNECT BY PRIOR se.organization_id_child
                        = se.organization_id_parent
                AND     org_structure_version_id = x_old_org_version_id
                START WITH se.organization_id_parent = x_old_start_org_id
                AND     org_structure_version_id = x_old_org_version_id
        UNION
                SELECT  x_old_start_org_id FROM Sys.dual ;
Line: 1563

        SELECT  se.organization_id_child organization_id
                FROM    per_org_structure_elements se
                WHERE   org_structure_version_id =  x_new_org_version_id
                AND     EXISTS (select 'X'
                        from hr_organization_information info
                        where info.organization_id = se.organization_id_child
                        and   info.org_information1 = 'PA_PROJECT_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y')
                CONNECT BY PRIOR se.organization_id_child
                        = se.organization_id_parent
                AND     org_structure_version_id = x_new_org_version_id
                START WITH se.organization_id_parent = x_new_start_org_id
                AND     org_structure_version_id = x_new_org_version_id
        UNION
                SELECT  x_new_start_org_id FROM Sys.dual -- Added exists clause for Bug# 1650520
                WHERE   EXISTS (select 'X'
                        from hr_organization_information info
                        where info.org_information1 = 'PA_PROJECT_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y'
                        and   info.organization_id = x_new_start_org_id);
Line: 1588

        SELECT  se.organization_id_child organization_id
                FROM    per_org_structure_elements se
                WHERE   org_structure_version_id =  x_new_org_version_id
                AND     EXISTS (select 'X'
                        from hr_organization_information info
                        where info.organization_id = se.organization_id_child
                        and   info.org_information1 = 'PA_EXPENDITURE_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y')
                CONNECT BY PRIOR se.organization_id_child
                        = se.organization_id_parent
                AND     org_structure_version_id = x_new_org_version_id
                START WITH se.organization_id_parent = x_new_start_org_id
                AND     org_structure_version_id = x_new_org_version_id
        UNION
                SELECT  x_new_start_org_id FROM Sys.dual
                 where  EXISTS (select 'X'  /* Made changes for BUG 1180635*/
                        from hr_organization_information info
                        where info.org_information1 = 'PA_EXPENDITURE_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y'
                        and   info.organization_id = x_new_start_org_id);
Line: 1628

        /* Update all Organizations (Projects or Expenditures)
           in the old hierarchy with inactive date as Sysdate.
           Union is to include the start organization id in the update */

        UPDATE pa_all_organizations
        SET    Inactive_Date    = TRUNC(SYSDATE)
        WHERE  Pa_Org_Use_Type  = x_org_use_type
        AND    Org_id = x_Org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
        AND    Organization_id  = rec_all_old_org.organization_id
	and inactive_date is null ; -- Bug Ref # 6367868
Line: 1645

                INSERT INTO  Pa_All_Organizations
                       (organization_id,
                        org_id,
                        pa_org_use_type,
                        inactive_date)
                 VALUES
                       (rec_all_old_org.organization_id,
                        x_org_id,
                        x_org_use_type,
                        TRUNC(SYSDATE));
Line: 1663

       /* Update all Organizations (Expenditures)
          in the new hierarchy with inactive date as NULL.
          Union is to include the start organization id in the update */

        UPDATE pa_all_organizations
        SET    Inactive_Date = NULL
        WHERE  Pa_Org_Use_Type = x_org_use_type
        AND    Org_id = x_Org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
        AND    Organization_id = rec_exp_new_org.organization_id;
Line: 1679

                INSERT INTO  Pa_All_Organizations
                       (organization_id,
                        org_id,
                        pa_org_use_type,
                        inactive_date)
                VALUES
                       (rec_exp_new_org.organization_id,
                        x_org_id,
                        x_org_use_type,
                        NULL);
Line: 1700

       /* Update all Organizations (Projects)
          in the new hierarchy with inactive date as NULL.
          Union is to include the start organization id in the update */

        UPDATE pa_all_organizations
        SET    Inactive_Date = NULL
        WHERE  Pa_Org_Use_Type = x_org_use_type
        AND    Org_id = x_Org_id --MOAC Changes: Bug 4363092: Removed nvl usage with org_id
        AND    Organization_id = rec_proj_new_org.organization_id;
Line: 1716

                INSERT INTO  Pa_All_Organizations
                       (organization_id,
                        org_id,
                        pa_org_use_type,
                        inactive_date)
                VALUES
                       (rec_proj_new_org.organization_id,
                        x_org_id,
                        x_org_use_type,
                        NULL);
Line: 1765

     INSERT INTO PA_ORG_HIERARCHY_DENORM ( parent_organization_id
                                        , child_organization_id
                                        , org_hierarchy_version_id
                                        , pa_org_use_type
                                        , creation_date
                                        , created_by
                                        , last_update_date
                                        , last_updated_by
                                        , last_update_login
                                          )
                              SELECT  p_parent_organization_id
                                    , p_child_organization_id
                                    , p_org_hierarchy_version_id
                                    , p_pa_org_use_type
                                    , sysdate
,1--                                    , TO_NUMBER(FND_PROFILE.VALUE('USER_ID'))
                                    , sysdate
,1--                                    , TO_NUMBER(FND_PROFILE.VALUE('USER_ID'))
,1--                                    , TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID'))
                               from dual
                               where not exists
                                    (select 'Y'
                                    from pa_org_hierarchy_denorm
                                   where pa_org_use_type = p_pa_org_use_type
                                     and parent_organization_id = p_parent_organization_id
                                     and child_organization_id = p_child_organization_id
                                     and org_hierarchy_version_id = p_org_hierarchy_version_id);
Line: 1865

     INSERT INTO pa_org_hierarchy_denorm ( parent_organization_id
                                        , child_organization_id
                                        , org_hierarchy_version_id
                                        , pa_org_use_type
                                        , creation_date
                                        , created_by
                                        , last_update_date
                                        , last_updated_by
                                        , last_update_login
                                        , parent_level
                                        , child_level
                                          )
                              SELECT  p_parent_organization_id
                                    , p_child_organization_id
                                    , p_org_hierarchy_version_id
                                    , p_pa_org_use_type
                                    , sysdate
,1--                                    , TO_NUMBER(FND_PROFILE.VALUE('USER_ID'))
                                    , sysdate
,1--                                    , TO_NUMBER(FND_PROFILE.VALUE('USER_ID'))
,1--                                    , TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID'))
                                        , p_parent_level
                                        , p_child_level
                               from dual
                               where not exists
                                    (select 'Y'
                                    from pa_org_hierarchy_denorm
                                   where pa_org_use_type = p_pa_org_use_type
                                     and parent_organization_id = p_parent_organization_id
                                     and child_organization_id = p_child_organization_id
                                     and org_hierarchy_version_id = p_org_hierarchy_version_id);
Line: 1936

     INSERT INTO pa_org_hierarchy_denorm
                                   ( parent_organization_id
                                   , child_organization_id
                                   , org_hierarchy_version_id
                                   , pa_org_use_type
                                   , creation_date
                                   , created_by
                                   , last_update_date
                                   , last_updated_by
                                   , last_update_login
                                   , parent_level
                                   , child_level
                                   , org_id
                                    )
                              SELECT  p_parent_organization_id
                                   , p_child_organization_id
                                   , p_org_hierarchy_version_id
                                   , p_pa_org_use_type
                                   , sysdate
                                   , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                                   , sysdate
                                   , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                                   , nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
                                   , p_parent_org_level
                                   , p_child_org_level
                                   , p_org_id
                               from dual
                               where not exists
                                (select 'Y'
                                 from pa_org_hierarchy_denorm
                                where pa_org_use_type = p_pa_org_use_type
                 and parent_organization_id = p_parent_organization_id
                 and child_organization_id = p_child_organization_id
                 and org_hierarchy_version_id = p_org_hierarchy_version_id
                 and nvl(org_id, -99) = nvl(p_org_id, -99));  /* 2976953 Added nvl condition for org_id */
Line: 2017

 SELECT P_organization_id_parent
    FROM dual
     UNION
  (SELECT distinct organization_id_parent
    FROM per_org_structure_elements
   WHERE org_structure_version_id = P_org_version_id
 CONNECT BY PRIOR organization_id_parent= organization_id_child
     AND org_structure_version_id = P_org_version_id
 START WITH organization_id_child = P_organization_id_parent
       AND org_structure_version_id = P_org_version_id
/* ---- The following query is added to fix the bug : 1654453 ---
 ---- since the start organization id defined in per_org_structure_elements
 ---- may be different from the start_organization_id set up in pa_implementations
 ---- so always the reporting hierarchy is formed based on pa_implementations
 ---- start_organization_id */
 MINUS
  SELECT distinct organization_id_parent
    FROM per_org_structure_elements
   WHERE org_structure_version_id = P_org_version_id
 CONNECT BY PRIOR organization_id_parent= organization_id_child
     AND org_structure_version_id = P_org_version_id
 START WITH organization_id_child = P_start_org_id
       AND org_structure_version_id = P_org_version_id)
 UNION
 (SELECT P_organization_id_child from dual);
Line: 2061

           SELECT  max(parent_level) into v_plevel
           FROM    pa_org_hierarchy_denorm
           WHERE   org_hierarchy_version_id = P_org_version_id
           and   pa_org_use_type = 'REPORTING'
           and   parent_organization_id =  v_parent_org_id
           and   org_id = p_org_id;
Line: 2069

             SELECT  max(child_level) into v_plevel
             FROM    pa_org_hierarchy_denorm
             WHERE   org_hierarchy_version_id = P_org_version_id
             and   pa_org_use_type = 'REPORTING'
             and   child_organization_id =  v_parent_org_id
             and   org_id = p_org_id;
Line: 2110

       SELECT  max(level)
        INTO  v_parent_org_level
         FROM    per_org_structure_elements
        WHERE    org_structure_version_id =  P_org_version_id
        AND     organization_id_parent =  v_parent_org_id
        CONNECT BY PRIOR organization_id_child = organization_id_parent
        AND  org_structure_version_id = P_org_version_id
        START WITH organization_id_parent = P_start_org_id
        AND   org_structure_version_id = P_org_version_id;
Line: 2121

       SELECT  max(level)
        INTO v_parent_org_level
         FROM    per_org_structure_elements
        WHERE    org_structure_version_id =  P_org_version_id
        AND     organization_id_child =  v_parent_org_id
        CONNECT BY PRIOR organization_id_child = organization_id_parent
        AND  org_structure_version_id = P_org_version_id
        START WITH organization_id_parent = P_start_org_id
        AND   org_structure_version_id = P_org_version_id;
Line: 2202

   SELECT  dummy_level plevel             --- This query is added to fix bug : 1619922
          ,start_org_id organization_id_parent
          ,start_org_id organization_id_child
    FROM   dual
   UNION
     SELECT  distinct
           level plevel
           ,organization_id_parent
           ,organization_id_child
     FROM  per_org_structure_elements
    WHERE org_structure_version_id = version_id
 CONNECT BY PRIOR  organization_id_child =  organization_id_parent
              and org_structure_version_id = version_id
 START WITH  organization_id_parent = start_org_id
         and org_structure_version_id = version_id
 ORDER  by 1;
Line: 2222

  (SELECT  organization_id_child
   FROM    per_org_structure_elements
   WHERE   org_structure_version_id = version_id
  CONNECT BY PRIOR  organization_id_child = organization_id_parent
               and org_structure_version_id = version_id
  START WITH   organization_id_parent = start_org_id
           and org_structure_version_id = version_id
    UNION
  SELECT   v_start_org_id
  FROM     sys.dual)
   INTERSECT
  (SELECT  p_organization_id_parent
   FROM    sys.dual );
Line: 2245

     delete from pa_cc_tp_schedule_line_lkp;
Line: 2254

     for imp_rec in ( select org_id, start_organization_id
                   from   pa_implementations_all imp
                   where  org_structure_version_id = p_org_version_id
                  )
    LOOP
    v_start_org_id := imp_rec.start_organization_id;
Line: 2268

            DELETE  from pa_org_hierarchy_denorm
            WHERE   pa_org_use_type = 'REPORTING'
            and   org_hierarchy_version_id = p_org_version_id
            and   nvl(org_id, -99) = nvl(v_org_id, -99);    /* 2976953-Added the nvl condition for org_id */
Line: 2288

        SELECT  max(level) into v_maximumlevel
        FROM  per_org_structure_elements
        WHERE  org_structure_version_id = p_org_version_id
        CONNECT BY PRIOR  organization_id_child =  organization_id_parent
               and org_structure_version_id = p_org_version_id
        START WITH  organization_id_parent = v_start_org_id
               and org_structure_version_id = p_org_version_id;
Line: 2365

    select 'X' into l_exist
    from pa_org_hierarchy_denorm
    where parent_organization_id = p_organization_id
    and org_hierarchy_version_id = p_org_structure_version_id
    and pa_org_use_type = p_org_structure_type
    and rownum = 1;
Line: 2401

    select 'X' into l_exist
    from pa_org_hierarchy_denorm
    where parent_organization_id = p_organization_id
    and pa_org_use_type = p_org_structure_type
    and rownum = 1;
Line: 2441

    select 'X' into l_exist
    from pa_org_hierarchy_denorm
    where org_hierarchy_version_id = p_org_structure_version_id
    and pa_org_use_type = p_org_structure_type
    and rownum = 1;
Line: 2480

        SELECT distinct
               imp.org_structure_version_id version_id
              ,imp.start_organization_id  start_org_id
        FROM   pa_implementations_all imp,
               per_org_structure_elements posg
        WHERE  posg.org_structure_version_id = imp.org_structure_version_id;
Line: 2562

/* this cursor will select all parents in the hierarchy below p_organization_id_parent
   including p_organization_id_parent. This cursor will not select leaf nodes
   for p_organization_id_parent = org3 it will return org3, org5,org6, org9 */

CURSOR all_parents (max_level number) IS
SELECT distinct organization_id_parent
,(max_level - level + 1) rev_level
FROM per_org_structure_elements a
WHERE a.org_structure_version_id = p_org_version_id
CONNECT BY PRIOR a.organization_id_child = a.organization_id_parent
AND a.org_structure_version_id = p_org_version_id
START WITH a.organization_id_parent = p_organization_id_parent
AND a.org_structure_version_id = p_org_version_id
ORDER by rev_level desc;
Line: 2584

     delete from pa_cc_tp_schedule_line_lkp;
Line: 2598

        /* delete from pa_org_hierarchy_denorm */

        DELETE from pa_org_hierarchy_denorm
        WHERE org_hierarchy_version_id = p_org_version_id
          AND nvl(org_id, -99) = nvl(p_org_id, -99)
          AND pa_org_use_type = 'REPORTING';  /* 2976953-Added nvl condition for org id and check for
Line: 2611

        SELECT MAX(level+1)
        INTO v_max_level
        FROM per_org_structure_elements a
        WHERE a.org_structure_version_id = p_org_version_id
        CONNECT BY PRIOR a.organization_id_child = a.organization_id_parent
        AND a.org_structure_version_id = p_org_version_id
        START WITH a.organization_id_parent = p_organization_id_parent
        AND a.org_structure_version_id = p_org_version_id;
Line: 2630

                for each parent insert all childs
                this will be called for each parent i.e. org3, org5, org6, org9
                For each parent it will insert all of its child at any level. Like
                for org3 it will insert org5-10 with their appropriate level
                */

                INSERT INTO pa_org_hierarchy_denorm
                ( parent_organization_id
                , child_organization_id
                , org_hierarchy_version_id
                , pa_org_use_type
                , creation_date
                , created_by
                , last_update_date
                , last_updated_by
                , last_update_login
                , parent_level
                , child_level
                , org_id
                 )
                (SELECT c1rec.organization_id_parent
                , organization_id_child
                , org_structure_version_id
                , 'REPORTING'
                , sysdate
                , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                , sysdate
                , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                , nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
                , c1rec.rev_level
                , c1rec.rev_level - level
                , p_org_id
                FROM per_org_structure_elements a
                WHERE a.org_structure_version_id = p_org_version_id
                CONNECT BY PRIOR a.organization_id_child = a.organization_id_parent
                AND a.org_structure_version_id = p_org_version_id
                START WITH a.organization_id_parent = c1rec.organization_id_parent
                AND a.org_structure_version_id = p_org_version_id
                );
Line: 2674

        /* now insert all organizations in the heirarchy under p_organization_id_parent
           into this table with parent and child organization id same. As all organizations
           in the heirarchy has to be a child of start org so select all childs from denorm
           table for this parent.
        */

        --mano_msg('now inserting for each child  ');
Line: 2682

        INSERT INTO pa_org_hierarchy_denorm
        ( parent_organization_id
        , child_organization_id
        , org_hierarchy_version_id
        , pa_org_use_type
        , creation_date
        , created_by
        , last_update_date
        , last_updated_by
        , last_update_login
        , parent_level
        , child_level
        , org_id
         )
        (SELECT child_organization_id
        , child_organization_id
        , org_hierarchy_version_id
        , 'REPORTING'
        , sysdate
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
        , sysdate
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
        , child_level
        , child_level
        , p_org_id
        FROM pa_org_hierarchy_denorm
        where org_hierarchy_version_id = p_org_version_id           -- org_hierarchy_version_id Changed via bug 2890156
          and nvl(org_id, -99) = nvl(p_org_id, -99)  /* 2976953-Added nvl to the org_id condition */
          and pa_org_use_type = 'REPORTING'    /* 2976953- Added this condition */
          and parent_organization_id = p_organization_id_parent
        UNION ALL
        SELECT p_organization_id_parent
        , p_organization_id_parent
        , p_org_version_id
        , 'REPORTING'
        , sysdate
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
        , sysdate
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
        , v_max_level
        , v_max_level
        , p_org_id
        FROM dual
        );
Line: 2777

select parent_organization_id, parent_level
from pa_org_hierarchy_denorm
where  org_hierarchy_version_id = x_org_version_id
       and child_organization_id = x_organization_id_parent
       and pa_org_use_type = 'REPORTING'
       and nvl(org_id, -99) = nvl(p_org_id, -99);
Line: 2791

  for imp_rec in ( select org_id
                   from   pa_implementations_all imp
                   where  org_structure_version_id = x_org_version_id
                  )
  loop

/* Get the level for the organization x_organization_id_parent */
/* The variable x_exists_in_denorm is to check whether the parent organization is
existing in pa_org_hierarchy_denorm table, if it is not there it means that the parent
organization is not in the reporting hierarchy below the reporting start organization */

       x_exists_in_denorm := 'Y';
Line: 2805

	     select unique parent_level into x_parent_level from pa_org_hierarchy_denorm
	     where org_hierarchy_version_id = x_org_version_id
	     and parent_organization_id = x_organization_id_parent
	     and child_organization_id = x_organization_id_parent
	     and pa_org_use_type = 'REPORTING'
	     and nvl(org_id, -99) = nvl(imp_rec.org_id, -99); /* 2976953 - Added nvl for the org id condition */
Line: 2857

               update pa_org_hierarchy_denorm
	       set parent_level = parent_level + 1,
	           child_level = child_level + 1
	       where org_hierarchy_version_id = x_org_version_id
                     and pa_org_use_type = 'REPORTING'
                     and nvl(org_id, -99) = nvl(imp_rec.org_id, -99); /* 2976953-Added nvl condition for org_id */
Line: 2909

pa_og_hierarchy_denorm for REPORTING pa_org_use_type when a organization is deleted from the hierarchy.
The call to this procedure will be made from maintain_org_hist_brd.
The deleted organization is x_organiation_id_child  */

procedure restructure_rpt_orgs_denorm(
                               x_org_version_id in number,
                               x_err_code in out NOCOPY number, --File.Sql.39 bug 4440895
                               x_err_stage in out NOCOPY varchar2, --File.Sql.39 bug 4440895
                               x_err_stack in out NOCOPY varchar2 --File.Sql.39 bug 4440895
			               )
				       IS
old_stack   VARCHAR2(2000);
Line: 2925

   Select 1
   from dual
   where exists
      (select 1 from pa_org_hierarchy_denorm
       where org_hierarchy_version_id = x_org_version_id and
             pa_org_use_type          = 'REPORTING' and
             nvl(org_id, -99)         = nvl(p_org_id, -99) and  /* 2976953 Added nvl for org_id condition */
	     parent_level = 1
      );
Line: 2943

  for imp_rec in ( select org_id
                   from   pa_implementations_all imp
                   where  org_structure_version_id = x_org_version_id
                  )
  loop

/* check_lower_org_exists is the cursor to find if there is any other organization also at the leaf level
as x_organization_id_child which was deleted, if yes no need to restructure the records else we need to decrement
all the levels so that other organization (s) which are actually now leaf nodes in the hierarchy have their levels as 1
and other organizations in the hierarchy have levels changed accordingly */

    open check_lower_org_exists(imp_rec.org_id);
Line: 2958

      update pa_org_hierarchy_denorm
      set parent_level = parent_level - 1,
          child_level = child_level - 1
          where org_hierarchy_version_id = x_org_version_id
                and pa_org_use_type = 'REPORTING'
                and nvl(org_id, -99) = nvl(imp_rec.org_id, -99); /* 2976953 Added nvl for org_id condition */
Line: 2977

/* Bug 3649799 - This procedure will be called by statement level trigger for update on
per_org_structure_elements. */

procedure maintain_org_hist_update(x_err_code                   in out  NOCOPY number, --File.Sql.39 bug 4440895
                                   x_err_stage                  in out  NOCOPY varchar2, --File.Sql.39 bug 4440895
                                   x_err_stack                  in out  NOCOPY varchar2)  is --File.Sql.39 bug 4440895


/* This cursor is to get all the parents for the organization l_start_org_id in hierarchy l_org_struct_ver_id */

CURSOR all_parents (max_level number,
                    l_org_struct_ver_id IN per_org_structure_elements.org_structure_version_id%TYPE,
		    l_start_org_id IN per_org_structure_elements.organization_id_child%TYPE) IS
SELECT distinct organization_id_parent
,(max_level - level + 1) rev_level
FROM per_org_structure_elements a
WHERE a.org_structure_version_id = l_org_struct_ver_id
CONNECT BY PRIOR a.organization_id_child = a.organization_id_parent
AND a.org_structure_version_id = l_org_struct_ver_id
START WITH a.organization_id_parent = l_start_org_id
AND a.org_structure_version_id = l_org_struct_ver_id
ORDER by rev_level desc;
Line: 3003

SELECT 'Y' FROM pa_implementations_all
WHERE proj_org_structure_version_id = c_org_struct_version_id
   OR exp_org_structure_version_id =  c_org_struct_version_id;
Line: 3018

SELECT  organization_id_child
    , l_level - level
    FROM per_org_structure_elements a
    WHERE a.org_structure_version_id = l_version_id
    CONNECT BY PRIOR a.organization_id_child = a.organization_id_parent
    AND a.org_structure_version_id = l_version_id
    START WITH a.organization_id_parent = l_org_id_parent
    AND a.org_structure_version_id = l_version_id;
Line: 3030

SELECT child_organization_id
        , child_level
        FROM pa_org_hierarchy_denorm
        where org_hierarchy_version_id = l_version_id
          and nvl(org_id, -99) = nvl(l_org_id, -99)
      and pa_org_use_type = 'REPORTING'
          and parent_organization_id = l_start_org_id;
Line: 3040

SELECT org_id FROM pa_implementations_all
               WHERE org_structure_version_id = l_version_id
               and start_organization_id = l_start_org_id;
Line: 3066

	select distinct org_structure_version_id
	into L_STR_VERSION_ID_TMP(L_STR_VERSION_ID_TMP.count+1)
	from per_org_structure_elements
	where
	ROWID = pa_org_utils.newRows(k);
Line: 3100

  SELECT org_structure_version_id, organization_id_parent, organization_id_child
  INTO l_version_id, l_new_parent_org_id, l_new_child_org_id
  FROM per_org_structure_elements
  WHERE ROWID = pa_org_utils.newRows(i); */
Line: 3109

  maintain_projexp_org_update(        p_version_id => l_version_id,
                                      p_org_use_type => 'PROJECTS',
				      x_err_code => x_err_code,
                                      x_err_stage => x_err_stage,
                                      x_err_stack => x_err_stack);
Line: 3115

  maintain_projexp_org_update(        p_version_id => l_version_id,
                                      p_org_use_type => 'EXPENDITURES',
				      x_err_code => x_err_code,
                                      x_err_stage => x_err_stage,
                                      x_err_stack => x_err_stack);
Line: 3135

For each org id which uses the hierarchy updated, we first delete the data from denorm table
Then get the maximum level in that hierarchy.
Then insert the appropriate combinations in the denorm table.
The code is similar to the populate_hierarchy_denorm2 procedure added in 115.25 version of this file */

/* Commented and added for bug#5952671
FOR imp_rec IN (SELECT org_id, start_organization_id FROM
               pa_implementations_all
	       WHERE org_structure_version_id = l_version_id) */
FOR imp_rec IN (SELECT distinct start_organization_id FROM
               pa_implementations_all
           WHERE org_structure_version_id = l_version_id)
LOOP
/* Commented for bug#5952671
	DELETE from pa_org_hierarchy_denorm
        WHERE org_hierarchy_version_id = l_version_id
          AND org_id = imp_rec.org_id
	  AND pa_org_use_type = 'REPORTING'; */
Line: 3155

        l_org_id_tbl.delete;
Line: 3161

          DELETE from pa_org_hierarchy_denorm
                WHERE org_hierarchy_version_id = l_version_id
                 AND nvl(org_id, -99) = nvl(l_org_id_tbl(i), -99)
             AND pa_org_use_type = 'REPORTING';
Line: 3168

        SELECT MAX(level+1)
        INTO v_max_level
        FROM per_org_structure_elements a
        WHERE a.org_structure_version_id = l_version_id
        CONNECT BY PRIOR a.organization_id_child = a.organization_id_parent
        AND a.org_structure_version_id = l_version_id
        START WITH a.organization_id_parent = imp_rec.start_organization_id
        AND a.org_structure_version_id = l_version_id;
Line: 3184

               l_child_organization_id_tbl.delete;
Line: 3185

               l_child_level_tbl.delete;
Line: 3192

                 FOR imp1_rec IN (SELECT org_id  FROM
                           pa_implementations_all
                       WHERE org_structure_version_id = l_version_id and start_organization_id = imp_rec.start_organization_id)
                 LOOP
                   forall i in l_child_organization_id_tbl.first..l_child_organization_id_tbl.last
                    INSERT INTO pa_org_hierarchy_denorm
                    ( parent_organization_id
                    , child_organization_id
                    , org_hierarchy_version_id
                    , pa_org_use_type
                    , creation_date
                    , created_by
                    , last_update_date
                    , last_updated_by
                    , last_update_login
                    , parent_level
                    , child_level
                    , org_id
                     ) values
                     (
                     c1rec.organization_id_parent
                    ,l_child_organization_id_tbl(i)
                    ,l_version_id
                    ,'REPORTING'
                    ,sysdate
                    ,nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                    ,sysdate
                    ,nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                    ,nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
                    ,c1rec.rev_level
                    ,l_child_level_tbl(i)
                    ,imp1_rec.org_id
                     );
Line: 3236

               l_child_organization_id_tbl.delete;
Line: 3237

               l_child_level_tbl.delete;
Line: 3244

                 FOR imp1_rec IN (SELECT org_id  FROM
                           pa_implementations_all
                       WHERE org_structure_version_id = l_version_id and start_organization_id = imp_rec.start_organization_id)
                 LOOP
                      FORALL i in l_child_organization_id_tbl.first..l_child_organization_id_tbl.last
                    INSERT INTO pa_org_hierarchy_denorm
                    ( parent_organization_id
                    , child_organization_id
                    , org_hierarchy_version_id
                    , pa_org_use_type
                    , creation_date
                    , created_by
                    , last_update_date
                    , last_updated_by
                    , last_update_login
                    , parent_level
                    , child_level
                    , org_id
                     ) values
                     (
                     l_child_organization_id_tbl(i)
                    ,l_child_organization_id_tbl(i)
                    ,l_version_id
                    ,'REPORTING'
                    ,sysdate
                    ,nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                    ,sysdate
                    ,nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                    ,nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
                    ,l_child_level_tbl(i)
                    ,l_child_level_tbl(i)
                    ,imp1_rec.org_id
                     );
Line: 3282

        FOR imp1_rec IN (SELECT org_id  FROM
               pa_implementations_all
               WHERE org_structure_version_id = l_version_id AND start_organization_id = imp_rec.start_organization_id)
        LOOP
            INSERT INTO pa_org_hierarchy_denorm
            ( parent_organization_id
            , child_organization_id
            , org_hierarchy_version_id
            , pa_org_use_type
            , creation_date
            , created_by
            , last_update_date
            , last_updated_by
            , last_update_login
            , parent_level
            , child_level
            , org_id
             ) VALUES
             (
             imp_rec.start_organization_id
            ,imp_rec.start_organization_id
            ,l_version_id
            ,'REPORTING'
            ,sysdate
            ,nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
            ,sysdate
            ,nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
            ,nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
            ,v_max_level
            ,v_max_level
            ,imp1_rec.org_id
             );
Line: 3318

                INSERT INTO pa_org_hierarchy_denorm
                ( parent_organization_id
                , child_organization_id
                , org_hierarchy_version_id
                , pa_org_use_type
                , creation_date
                , created_by
                , last_update_date
                , last_updated_by
                , last_update_login
                , parent_level
                , child_level
                , org_id
                 )
                (SELECT c1rec.organization_id_parent
                , organization_id_child
                , l_version_id
                , 'REPORTING'
                , sysdate
                , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                , sysdate
                , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
                , nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
                , c1rec.rev_level
                , c1rec.rev_level - level
                , imp_rec.org_id
                FROM per_org_structure_elements a
                WHERE a.org_structure_version_id = l_version_id
                CONNECT BY PRIOR a.organization_id_child = a.organization_id_parent
                AND a.org_structure_version_id = l_version_id
                START WITH a.organization_id_parent = c1rec.organization_id_parent
                AND a.org_structure_version_id = l_version_id
                );
Line: 3354

        INSERT INTO pa_org_hierarchy_denorm
        ( parent_organization_id
        , child_organization_id
        , org_hierarchy_version_id
        , pa_org_use_type
        , creation_date
        , created_by
        , last_update_date
        , last_updated_by
        , last_update_login
        , parent_level
        , child_level
        , org_id
         )
        (SELECT child_organization_id
        , child_organization_id
        , org_hierarchy_version_id
        , 'REPORTING'
        , sysdate
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
        , sysdate
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
        , child_level
        , child_level
        , imp_rec.org_id
        FROM pa_org_hierarchy_denorm
        where org_hierarchy_version_id = l_version_id
          and org_id = imp_rec.org_id
          and pa_org_use_type = 'REPORTING'   --  Added for bug#5361709
          and parent_organization_id = imp_rec.start_organization_id
        UNION ALL
        SELECT imp_rec.start_organization_id
        , imp_rec.start_organization_id
        , l_version_id
        , 'REPORTING'
        , sysdate
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
        , sysdate
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('USER_ID')),1)
        , nvl(TO_NUMBER(FND_PROFILE.VALUE('LOGIN_ID')),1)
        , v_max_level
        , v_max_level
        , imp_rec.org_id
        FROM dual
        ); */
Line: 3405

END maintain_org_hist_update;
Line: 3410

procedure maintain_projexp_org_update(p_version_id in number,
                                      p_org_use_type in varchar2,
				      x_err_code                   in out  NOCOPY number, --File.Sql.39 bug 4440895
                                      x_err_stage                  in out  NOCOPY varchar2, --File.Sql.39 bug 4440895
                                      x_err_stack                  in out  NOCOPY varchar2)  is --File.Sql.39 bug 4440895
l_imp_proj_exp VARCHAR2(1);
Line: 3422

SELECT decode(p_org_use_type, 'PROJECTS', proj_start_org_id, 'EXPENDITURES', exp_start_org_id) start_organization_id
FROM   pa_implementations_all imp
WHERE  decode(p_org_use_type, 'PROJECTS', proj_org_structure_version_id,
                   'EXPENDITURES', exp_org_structure_version_id) = c_version_id;
Line: 3431

SELECT c_start_org_id FROM dual
UNION ALL
SELECT organization_id_child
FROM per_org_structure_elements
WHERE org_structure_version_id = c_org_struct_ver_id
 CONNECT BY PRIOR organization_id_child = organization_id_parent
  AND org_structure_version_id =  c_org_struct_ver_id
 START WITH organization_id_parent = c_start_org_id
  AND org_structure_version_id = c_org_struct_ver_id;
Line: 3443

SELECT c_org_id
FROM dual
UNION ALL
SELECT organization_id_child
FROM per_org_structure_elements
WHERE org_structure_version_id = c_org_struct_ver_id
  CONNECT BY PRIOR organization_id_child = organization_id_parent
     AND org_structure_version_id = c_org_struct_ver_id
  START WITH organization_id_parent = c_org_id
     AND org_structure_version_id = c_org_struct_ver_id ;
Line: 3458

      SELECT 'Y' INTO l_imp_proj_exp
      FROM pa_implementations_all
      WHERE decode(p_org_use_type, 'PROJECTS', proj_org_structure_version_id,
                   'EXPENDITURES', exp_org_structure_version_id) = p_version_id
      AND ROWNUM = 1;
Line: 3464

      DELETE FROM pa_org_hierarchy_denorm
      WHERE org_hierarchy_version_id = p_version_id
            AND pa_org_use_type = p_org_use_type;
Line: 3476

       SELECT 'Y' INTO l_exist_recs
       FROM pa_org_hierarchy_denorm
       WHERE org_hierarchy_version_id = p_version_id
       AND pa_org_use_type = p_org_use_type
       AND parent_organization_id = imp_rec.start_organization_id
       AND ROWNUM = 1;
Line: 3497

                         SELECT 'YES' INTO class_org_true
                           FROM hr_organization_information
                          WHERE organization_id = l_child_org_id
                            AND ORG_INFORMATION_CONTEXT = 'CLASS'
                            AND ORG_INFORMATION1 = decode(p_org_use_type, 'PROJECTS', 'PA_PROJECT_ORG',
			                                  'EXPENDITURES', 'PA_EXPENDITURE_ORG')
                            AND ORG_INFORMATION2 = 'Y';
Line: 3524

END maintain_projexp_org_update;
Line: 3539

        SELECT  se.organization_id_child organization_id
                FROM    per_org_structure_elements se
                WHERE   org_structure_version_id =  x_org_version_id
                AND     EXISTS (select 'X'
                        from hr_organization_information info
                        where info.organization_id = se.organization_id_child
                        and   info.org_information1 = 'PA_PROJECT_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y')
                CONNECT BY PRIOR se.organization_id_child
                        = se.organization_id_parent
                AND     org_structure_version_id = x_org_version_id
                START WITH se.organization_id_parent = v_start_org_id
                AND     org_structure_version_id = x_org_version_id
        UNION
                SELECT  v_start_org_id FROM Sys.dual -- Added exists clause for Bug# 1650520
                WHERE   EXISTS (select 'X'
                        from hr_organization_information info
                        where info.org_information1 = 'PA_PROJECT_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y'
                        and   info.organization_id = v_start_org_id);
Line: 3563

        SELECT  se.organization_id_child organization_id
                FROM    per_org_structure_elements se
                WHERE   org_structure_version_id =  x_org_version_id
                AND     EXISTS (select 'X'
                        from hr_organization_information info
                        where info.organization_id = se.organization_id_child
                        and   info.org_information1 = 'PA_EXPENDITURE_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y')
                CONNECT BY PRIOR se.organization_id_child
                        = se.organization_id_parent
                AND     org_structure_version_id = x_org_version_id
                START WITH se.organization_id_parent = v_start_org_id
                AND     org_structure_version_id = x_org_version_id
        UNION
                SELECT  v_start_org_id FROM Sys.dual
                 where  EXISTS (select 'X'  /* Made changes for BUG 1180635*/
                        from hr_organization_information info
                        where info.org_information1 = 'PA_EXPENDITURE_ORG'
                        and   info.org_information_context||'' = 'CLASS'
                        and   info.org_information2 = 'Y'
                        and   info.organization_id = v_start_org_id);
Line: 3590

  for imp_rec in ( select org_id,proj_start_org_id
                   from   pa_implementations_all imp
                   where  proj_org_structure_version_id = x_org_version_id
                  )

  loop
    v_start_org_id := imp_rec.proj_start_org_id;
Line: 3599

        UPDATE pa_all_organizations
        SET    Inactive_Date    = TRUNC(SYSDATE)
        WHERE  Pa_Org_Use_Type  = 'PROJECTS'
        AND    NVL(Org_id, -99) = NVL(v_org_id, -99);
Line: 3606

       /* Update all Organizations (Projects)
          in the  hierarchy with inactive date as NULL.
          Union is to include the start organization id in the update */

        UPDATE pa_all_organizations
        SET    Inactive_Date = NULL
        WHERE  Pa_Org_Use_Type = 'PROJECTS'
        AND    NVL(Org_id, -99) = NVL(v_org_id, -99)
        AND    Organization_id = rec_proj_new_org.organization_id;
Line: 3622

                INSERT INTO  Pa_All_Organizations
                       (organization_id,
                        org_id,
                        pa_org_use_type,
                        inactive_date)
                VALUES
                       (rec_proj_new_org.organization_id,
                        v_org_id,
                        'PROJECTS',
                        NULL);
Line: 3637

  for imp_rec in ( select org_id, exp_start_org_id
                   from   pa_implementations_all imp
                   where  exp_org_structure_version_id = x_org_version_id
                  )

  loop
    v_start_org_id := imp_rec.exp_start_org_id;
Line: 3646

        UPDATE pa_all_organizations
        SET    Inactive_Date    = TRUNC(SYSDATE)
        WHERE  Pa_Org_Use_Type  = 'EXPENDITURES'
        AND    NVL(Org_id, -99) = NVL(v_org_id, -99);
Line: 3653

       /* Update all Organizations (Projects)
          in the  hierarchy with inactive date as NULL.
          Union is to include the start organization id in the update */

        UPDATE pa_all_organizations
        SET    Inactive_Date = NULL
        WHERE  Pa_Org_Use_Type = 'EXPENDITURES'
        AND    NVL(Org_id, -99) = NVL(v_org_id, -99)
        AND    Organization_id = rec_exp_new_org.organization_id;
Line: 3669

                INSERT INTO  Pa_All_Organizations
                       (organization_id,
                        org_id,
                        pa_org_use_type,
                        inactive_date)
                VALUES
                       (rec_exp_new_org.organization_id,
                        v_org_id,
                        'EXPENDITURES',
                        NULL);