cancel
Showing results for 
Search instead for 
Did you mean: 

how to do dynamic selection of hierarchies during query execution based on cost center ?

Former Member
0 Kudos

Hi Gurus,

Scenario:

Cost center- User selection

Based on this should dynamically select hierarchy for cost element.(there are multiple hierarchies maintained for cost element)

Also cost center to hierarchy is one to one, the relationship is maintained in DSo- 'ZXXXXX'

Eg: CostCenter1   Hierarchy1

       Costcenter2    Hierarchy2

       Costcenter3    Hierarchy1

       Costcenter4    Hierarchy3

So during query run time, when user key in 'costcenter1' the query should pick up 'hierarchy1' and diplay.

Is it possible? how to achieve this?

Thanks in advance.

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Gurus,

Let me try it and then could brief on the outcome.

thanks.

umashankar_poojar
Active Contributor
0 Kudos

Hi Amala,

         Do you have any other attributes for each hierarchies? like version 100 for Hierarchy1 and 200 for Hierarchy2...if possible use the version attribute. Then by hierarchy node variables OR version you can fetch hierarchies easily.

Explore on this, if not Gajesh Nageshalready mentioned to write a customer exit to fetch the right hierarchy.

Thanks,

Umashankar

Former Member
0 Kudos

Hi Umashankar,

There is no other attribute. I checked it i doesn't have version. All the hierarchies that are to be used are custom hierarchies maintained by functional.

Former Member
0 Kudos

Create a customer Exit hierarchy variable VAR2 (NOT a hierarchy node variable)´. You do this in the hierarchy tab of the char.

Then write the user exit coding to read the variable value selected for the CC (VAR1), get the corresponding hierarchy from your lookup DSO, and parse that hierarchy value to your hierarchy variable VAR2

Former Member
0 Kudos

Hi Fr,

This is the code i used.

DATA :

          L_S_RANGE TYPE RSR_S_RANGESID,

           ls_varrange TYPE RRRANGEEXIT.

CASE I_VNAM.

    WHEN 'ZXXXXX'. <hierarchy variable of cost element>

  IF i_step = 2.

    READ TABLE i_t_var_range INTO ls_varrange WITH KEY vnam = '(cost center variable- user entry').

       CLEAR L_S_RANGE.

       l_s_range-sign = 'I'.

       l_s_range-opt   = 'EQ'.

       l_s_range-high = '0HIER_NODE'.<Info object name>

       l_s_range-low = '1'.<node id>

       APPEND l_s_range TO e_t_range.

     ENDIF.

     ENDCASE.


But when i try to open the query in BEX analyser, it throws error saying  'Variable has too many values'.

Based on cost center (user entry) should display related cost element hierarchy, also there are multiple hierarchies maintained for cost element.

Also i am not sure about the code also.

Former Member
0 Kudos

I don't have any experience with coding such a scenario, so i can't give you  a solution, but when looking at your code i see a couple of things:

  • on the one hand you create a hierarchy variable (so you can dynamically define which hierarchy is used for display), but in the code you move 0HIER_NODE  to the high-Parameter. I don' see why this yould have to go into the high-Parameter, i don't even see why you Need this value. 0HIER_NODE will be used yhen filtering on a hierarchy, not for display i think
  • You also move '1' to the low-paramter. Why?
Former Member
0 Kudos

I got this code through analyzing various code in different forums. I am not sure about the code.

Can you help me with the code?

former_member186399
Active Contributor
0 Kudos

Dear Amala,

Try using a customer exit variable for where in you can get the variable value of cost center and pass this value to get the hierarchy node for cost element

Regards

Gajesh

Former Member
0 Kudos

Hi Gajesh,

I am not an expert in abap.

This is the code i used.

DATA :

          L_S_RANGE TYPE RSR_S_RANGESID,

           ls_varrange TYPE RRRANGEEXIT.

CASE I_VNAM.

    WHEN 'ZXXXXX'. <hierarchy variable of cost element>

  IF i_step = 2.

    READ TABLE i_t_var_range INTO ls_varrange WITH KEY vnam = '(cost center variable- user entry').

       CLEAR L_S_RANGE.

       l_s_range-sign = 'I'.

       l_s_range-opt   = 'EQ'.

       l_s_range-high = '0HIER_NODE'.<Info object name>

       l_s_range-low = '1'.<node id>

       APPEND l_s_range TO e_t_range.

     ENDIF.

     ENDCASE.


But when i try to open the query in BEX analyser, it throws error saying  'Variable has too many values'.

Based on cost center (user entry) should display related cost element hierarchy, also there are multiple hierarchies maintained for cost element.

Also i am not sure about the code also.

need your help