Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Algorithm For Cost Element Group Hierarchy

Former Member
0 Likes
1,811

Hello. I hope you can help me.

I used the BAPI_COSTELEMENTGRP_GETDETAIL function in order to get the cost elements, but i need also the hierarchy that is given in the returning table of the function and for example it is shown:


This table using and algorithm can give me the follow hierarchy:

I would like that the algorithm give me a table with for example:

MOD

Personal Expenses / Remunerations / Salaries

Personal Expenses / Remunerations / Commissions,

etc.

I tried the following:

But is not working. I hope you can help me.

Greetings

1 ACCEPTED SOLUTION
Read only

MateuszAdamus
Active Contributor
0 Likes
1,697

Hello hvillanueva

Try this (might contain some typos).

DATA:
  lv_description TYPE string,
  lt_descriptions TYPE TABLE OF string.

lwa_desc-sign = 'I'.
lwa_desc-option = 'EQ'.

LOOP AT lt_hierarchynodes REFERENCE INTO DATA(ld_node).
  DATA(lv_hierarchy_level_index) = ld_node->hierlevel + 1.
  DELETE lt_descriptions FROM lv_hierarchy_level_index.
  lv_description = ld_node->descript.
  APPEND lv_description TO lt_descriptions.

  IF ld_node->valcount > 0.
    CLEAR lwa_desc-low.
    LOOP AT lt_descriptions INTO lv_description.
      CONCATENATE lwa_desc-low lv_description INTO lwa_desc-low SEPARATED BY space.
    ENDLOOP.
    CONDENSE lwa_desc-low.
    APPEND lwa_desc TO lr_desc.
  ENDIF.
ENDLOOP.
Kind regards,
Mateusz
5 REPLIES 5
Read only

Former Member
0 Likes
1,697

I tried the following but is not working:

LOOP AT lt_hierarchynodes ASSIGNING FIELD-SYMBOL(<fs_nodevalues>).
CLEAR lwa_desc.
AT NEW hierlevel.

ENDAT.
lwa_desc-sign = 'I'.
lwa_desc-option = 'EQ'.
CONCATENATE l_desc space <fs_nodevalues>-descript INTO l_desc.
lwa_desc-low = l_desc.
IF <fs_nodevalues>-valcount = 1.
APPEND lwa_desc TO lr_desc.
CLEAR l_desc.
ENDIF.
ENDLOOP.

Read only

MateuszAdamus
Active Contributor
0 Likes
1,698

Hello hvillanueva

Try this (might contain some typos).

DATA:
  lv_description TYPE string,
  lt_descriptions TYPE TABLE OF string.

lwa_desc-sign = 'I'.
lwa_desc-option = 'EQ'.

LOOP AT lt_hierarchynodes REFERENCE INTO DATA(ld_node).
  DATA(lv_hierarchy_level_index) = ld_node->hierlevel + 1.
  DELETE lt_descriptions FROM lv_hierarchy_level_index.
  lv_description = ld_node->descript.
  APPEND lv_description TO lt_descriptions.

  IF ld_node->valcount > 0.
    CLEAR lwa_desc-low.
    LOOP AT lt_descriptions INTO lv_description.
      CONCATENATE lwa_desc-low lv_description INTO lwa_desc-low SEPARATED BY space.
    ENDLOOP.
    CONDENSE lwa_desc-low.
    APPEND lwa_desc TO lr_desc.
  ENDIF.
ENDLOOP.
Kind regards,
Mateusz
Read only

0 Likes
1,697

Thanks you!! it works perfectly.

Read only

0 Likes
1,697

Thanks you!! it works perfectly.

Read only

0 Likes
1,697

That's good to hear.


Kind regards,
Mateusz