user2995784
user2995784

Reputation: 1

Oracle flex value hierarchy SQL query for oracle ebs r12 report

I am new to oracle and oracle ebs and I need some help.

I am doing a report in oracle ebs r12 and I need to list flex values from fnd_flex_values_vl view in a hierarchical way using a SQL query. It doesn`t necessary has to be a hierarchial query. Any query will do. I just need a SQL statement that will return me flex values in their hierarchial way.

There are two objects, that store information about flex values hierarchy. It is FND_FLEX_VALUE_NORM_HIERARCHY (table) and fnd_flex_value_children_v (view). I assume one of these is enough, since fnd_flex_value_children_v is made using FND_FLEX_VALUE_NORM_HIERARCHY and some other objects.

However, the problem I faced is, that several parents may be listed for one flex value and that I need to find all top parents or leaves in order to do an up-bottom or bottom-up hierarchy. As far as I understand fnd_flex_value_children_v doesn`t necessary store top parents (stores only children).

Also it seems that there is probably not one, but there may be multiple hierarchies (if so, I need to list them all in one query).

Your help will be really appreciated. I`ve been struggling with this one quite a while. Thank you very much for your attention.

Best regards, new user. =)

Upvotes: 0

Views: 29828

Answers (3)

Andy Haack
Andy Haack

Reputation: 484

This SQL from the Blitz Report library returns the hierarchy structure based on fnd_flex_value_norm_hierarchy with all containing child flex values: https://www.enginatics.com/reports/fnd-flex-value-hierarchy/

select
lpad(' ',2*(level-1))||level level_,
lpad(' ',2*(level-1))||ffvnh.parent_flex_value value,
ffvv.description,
decode(ffvnh.range_attribute,'P','Parent','C','Child') range_attribute,
ffvnh.child_flex_value_low,
ffvnh.child_flex_value_high,
decode(connect_by_isleaf,1,'Yes') is_leaf,
connect_by_root ffvnh.parent_flex_value root_value,
substr(sys_connect_by_path(ffvnh.parent_flex_value,'-> '),4) path,
ffvnh.parent_flex_value value_flat
from
(
select
ffvnh.parent_flex_value,
ffvnh.child_flex_value_low,
ffvnh.child_flex_value_high,
ffvnh.range_attribute,
ffvnh.flex_value_set_id
from
fnd_flex_value_norm_hierarchy ffvnh
where
ffvnh.flex_value_set_id=(select ffvs.flex_value_set_id from fnd_flex_value_sets ffvs where ffvs.flex_value_set_name=:flex_value_set_name)
union all
select
ffv2.flex_value parent_flex_value,
null child_flex_value_low,
null child_flex_value_high,
'x' range_attribute,
ffv2.flex_value_set_id
from
fnd_flex_values ffv2
where
2=2 and
ffv2.summary_flag='N' and
ffv2.flex_value_set_id=(select ffvs.flex_value_set_id from fnd_flex_value_sets ffvs where ffvs.flex_value_set_name=:flex_value_set_name)
) ffvnh,
fnd_flex_values_vl ffvv
where
3=3 and
ffvnh.parent_flex_value=ffvv.flex_value and
ffvnh.flex_value_set_id=ffvv.flex_value_set_id
connect by nocycle
ffvnh.parent_flex_value between prior ffvnh.child_flex_value_low and prior ffvnh.child_flex_value_high and
decode(nvl(prior ffvnh.range_attribute,'P'),'P','Y','N')=ffvv.summary_flag
start with
ffvnh.parent_flex_value=:parent_flex_value and
1=1 and
(:parent_flex_value is not null or
not exists (select null from
fnd_flex_value_norm_hierarchy ffvnh0
where
ffvnh0.flex_value_set_id=(select ffvs.flex_value_set_id from fnd_flex_value_sets ffvs where ffvs.flex_value_set_name=:flex_value_set_name) and
ffvnh.parent_flex_value between ffvnh0.child_flex_value_low and ffvnh0.child_flex_value_high and
ffvv.summary_flag=decode(ffvnh0.range_attribute,'P','Y','N')
)
)

To see all hierarchies (different parent top values), remove the 'start with' restriction to the parent flex value:

ffvnh.parent_flex_value=:parent_flex_value

Upvotes: 0

Mauricio Ch
Mauricio Ch

Reputation: 11

May be this can help u

SELECT fvc.PARENT_FLEX_VALUE RUBRO_N0 ,FVT.description
DESC_RUBRO_N0,FVC.FLEX_VALUE RUBRO_N1 , fvc.DESCRIPTION
DESC_RUBRO_N1,FVC2.FLEX_VALUE RUBRO_N2 , FVC2.DESCRIPTION
DESC_RUBRO_N2,FVC3.FLEX_VALUE RUBRO_N3 , FVC3.DESCRIPTION
DESC_RUBRO_N3,FVC4.FLEX_VALUE RUBRO_N4 , FVC4.DESCRIPTION
DESC_RUBRO_N4,NVL(FVC4.FLEX_VALUE,NVL(FVC3.FLEX_VALUE,NVL(FVC2.FLEX_VALUE,FVC.FLEX_VALUE))) RUBROFIN
FROM FND_FLEX_VALUE_CHILDREN_V fvc 
,FND_FLEX_VALUE_CHILDREN_V FVC2 
,FND_FLEX_VALUE_CHILDREN_V FVC3 
,FND_FLEX_VALUE_CHILDREN_V FVC4
,FND_FLEX_VALUES_TL FVT 
WHERE fvc.FLEX_VALUE_SET_ID =  1016176 
AND fvc.PARENT_FLEX_VALUE not in(SELECT FLEX_VALUE FROM FND_FLEX_VALUE_CHILDREN_V WHERE FLEX_VALUE_SET_ID = --YOUR FLEX_VALUE_SET_ID) 
AND fvc.FLEX_VALUE = FVC2.PARENT_FLEX_VALUE (+) 
AND fvc2.FLEX_VALUE = FVC3.PARENT_FLEX_VALUE (+) 
AND fvc3.FLEX_VALUE  = FVC4.PARENT_FLEX_VALUE (+) 
AND fvc.PARENT_FLEX_VALUE = FVT.FLEX_VALUE_MEANING 
AND FVT.SOURCE_LANG = 'ESA'
AND FVT.LANGUAGE = 'ESA' AND FVT.LAST_UPDATE_LOGIN NOT IN (0) 
ORDER BY 1,2,3,5,7
;

Best Regards

Upvotes: 0

Patrick Bacon
Patrick Bacon

Reputation: 4660

You should use the table, APPLSYS.FND_FLEX_VALUE_SETS. The objects you identify are metadata objects about the FND_FLEX_VALUE_SETS table.

I like to start with the root record.

Here is my method to find root records (no parent).

SELECT DISTINCT
FVS.PARENT_FLEX_VALUE_SET_ID
FROM
APPLSYS.FND_FLEX_VALUE_SETS FVS
WHERE
FVS.PARENT_FLEX_VALUE_SET_ID  IS NOT NULL 
ORDER BY 1 ;  

Once I find the root record, I develop my start by clause:

START WITH
(
FVS.FLEX_VALUE_SET_ID IN
(SELECT DISTINCT FVS.PARENT_FLEX_VALUE_SET_ID
FROM APPLSYS.FND_FLEX_VALUE_SETS FVS
WHERE FVS.PARENT_FLEX_VALUE_SET_ID IS NOT NULL
)

This clause does capture all root records (you could select just one).

Next, I develop my connect by clause. Since I want my hierarchy to start at the root, I would take this approach:

level 1 flex_value_set_id ....prior level

level 2 parent_flex_value_set_id

CONNECT BY fvs.parent_flex_value_set_id = prior fvs.flex_value_set_id ;

This results in this statement:

SELECT LEVEL,
FVS.*
FROM APPLSYS.FND_FLEX_VALUE_SETS FVS
START WITH
(
FVS.FLEX_VALUE_SET_ID IN
(SELECT DISTINCT FVS.PARENT_FLEX_VALUE_SET_ID
FROM APPLSYS.FND_FLEX_VALUE_SETS FVS
WHERE FVS.parent_flex_value_set_id IS NOT NULL
)
)
CONNECT BY FVS.PARENT_FLEX_VALUE_SET_ID = PRIOR FVS.FLEX_VALUE_SET_ID ; 

One then can add the flex values as follows:

SELECT  
LEVEL, 
FVS.* 
FROM  
(SELECT 
 FLEX.FLEX_VALUE_SET_ID, 
 FLEX.PARENT_FLEX_VALUE_SET_ID, 
 FLEX.FLEX_VALUE_SET_NAME, 
 FVAL.FLEX_VALUE 
 FROM 
 APPLSYS.FND_FLEX_VALUE_SETS FLEX, 
 APPLSYS.FND_FLEX_VALUES FVAL 
 WHERE 
 FLEX.FLEX_VALUE_SET_ID = FVAL.FLEX_VALUE_SET_ID(+)) FVS 
 START WITH 
 (FVS.FLEX_VALUE_SET_ID IN 
  (SELECT DISTINCT 
   FVS.PARENT_FLEX_VALUE_SET_ID 
   FROM APPLSYS.FND_FLEX_VALUE_SETS FVS 
   WHERE FVS.parent_flex_value_set_id IS NOT NULL ) ) 
   CONNECT BY 
   FVS.PARENT_FLEX_VALUE_SET_ID = PRIOR FVS.FLEX_VALUE_SET_ID;

Upvotes: 0

Related Questions