Tuesday, August 20, 2013

Business Groups / LE / OU / INV Query

Try the following ...
1) For Business Groups

select
o.organization_id ,
o.organization_id ,
otl.name ,
o.date_from ,
o.date_to ,
o.internal_address_line ,
o.location_id ,
o.comments ,
o2.org_information1 ,
o2.org_information2 ,
o2.org_information3 ,
o2.org_information4 ,
o3.org_information1 ,
o3.org_information2 ,
o3.org_information3 ,
o3.org_information4 ,
o3.org_information5 ,
o3.org_information6 ,
o3.org_information7 ,
o3.org_information8 ,
o3.org_information9 ,
o3.org_information10 ,
o3.org_information14 ,
o4.org_information2 ,
o3.org_information15 ,
o3.org_information16
from hr_all_organization_units o ,
hr_all_organization_units_tl otl ,
hr_organization_information o2 ,
hr_organization_information o3 ,
hr_organization_information o4
where o.organization_id = otl.organization_id
and o.organization_id = o2.organization_id (+)
and o.organization_id = o3.organization_id
and o.organization_id = o4.organization_id
and o3.org_information_context = 'Business Group Information'
and o2.org_information_context (+) = 'Work Day Information'
and o4.org_information_context = 'CLASS'
and o4.org_information1 = 'HR_BG'
and o4.org_information2 = 'Y'

2) For LEs :-

start with the same query as above but replace the 2 AND conditions for the columns shown as below ...

and o3.org_information_context = 'Legal Entity Accounting'
and o4.org_information1 = 'HR_LEGAL'

3) For OUs:-

start with the same query as above but replace the 2 AND conditions for the columns shown as below ...

and o3.org_information_context = 'Operating Unit Information'
and o4.org_information1 = 'OPERATING_UNIT'

4) For IOs:-

start with the same query as above but replace the 2 AND conditions for the columns shown as below ...

and o3.org_information_context = 'Accounting Information'
and o4.org_information1 = 'INV'

And finally, if you want to show OU, LE, SOB and SOB currency for your inv orgs, you can use this:

SELECT
o.organization_id
, otl.name
, o.date_from
, o.date_to
, o.internal_address_line
, loc.location_code as location
, o.comments
, les.business_group_id
, otl2.name as business_group
, les.organization_id as le_id
, les.name as legal_entity
, les.set_of_books_id
, sob.name as set_of_books
, sob.short_name
, sob.currency_code as currency
, opu.organization_id as ou_id
, opu.name as operating_unit
, les.vat_registration_number
FROM
hr_all_organization_units o
, hr_all_organization_units_tl otl
, hr_organization_information o2
, hr_organization_information o3
, hr_organization_information o4
, hr_legal_entities les
, hr_all_organization_units otl2
, hr_locations loc
, hr_operating_units opu
, gl_sets_of_books sob
where 1=1
and o.organization_id = otl.organization_id
AND o.organization_id = o2.organization_id (+)
and o.organization_id = o3.organization_id
and o.organization_id = o4.organization_id
AND o3.org_information_context = 'Accounting Information'
and o2.org_information_context (+) = 'Work Day Information'
and o4.org_information_context = 'CLASS'
and o4.org_information1 = 'INV'
and o4.org_information2 = 'Y'
and o3.org_information2 = les.organization_id
and les.business_group_id = otl2.organization_id
and o.location_id = loc.location_id(+)
and o3.org_information3 = opu.organization_id
and les.set_of_books_id = sob.set_of_books_id
order by o.organization_id