Application Development 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: 

How to get Cost element group

Former Member
0 Kudos

Hi,

I am creating one report, here i have <b>cost element</b> and <b>cost center</b>. using cost element how i will get <b>cost elementgroup</b>. using cost center how i will get <b>cost center group</b>. can any one please give idea. its urgent

point will be sure.

Mohana

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi

Cost element groups and cost centre groups are stored in Sets. Table SETLEAF

Also check

<a href="/people/pavan.p/blog/2007/01/12/understanding-sets-in-sap-r3:///people/pavan.p/blog/2007/01/12/understanding-sets-in-sap-r3

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/wiki?path=/pages/viewpage.action&pageid=54779">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/wiki?path=/pages/viewpage.action&pageid=54779</a>

Regards,

Arun

2 REPLIES 2

Former Member
0 Kudos

<b><i>HI MOHANA!!!</i></b>

<b>Use this subroutine with following parameters:</b>

p_class = '0101'

p_sname = 'Your Cost Group'

&----


*& Form f_get_id

&----


  • text

----


  • -->NODES text

  • -->LEAFS text

  • -->P_CLASS text

  • -->P_SNAME text

----


FORM f_get_id TABLES nodes TYPE nodes " Units of a set

leafs TYPE leafs " Leaves of a set

USING p_class TYPE rgsbs-class " Class of a set

p_sname TYPE c. "Name of a set

DATA:

setid LIKE sethier-setid, " ID a data set

info LIKE grphinfo, " For FM K_HIERARCHY_TABLES_READ....

overwr LIKE sy-datar.

" Search of a data set

REFRESH: nodes, leafs.

CALL FUNCTION 'G_SET_ENCRYPT_SETID'

EXPORTING

setclass = p_class

shortname = p_sname

kokrs = kokrs

ktopl = ktopl

IMPORTING

setid = setid

EXCEPTIONS

OTHERS = 1.

IF sy-subrc NE 0.

MESSAGE e009(zmco_costs_estimate) WITH p_sname p_class.

ENDIF.

CALL FUNCTION 'K_HIERARCHY_TABLES_READ'

EXPORTING

e_class = p_class

e_setid = setid

e_kokrs = kokrs

TABLES

t_nodes = nodes

t_values = leafs

CHANGING

c_info = info

c_overwrite = overwr

EXCEPTIONS

set_not_found = 1

OTHERS = 2.

CASE sy-subrc.

WHEN 0.

WHEN 1.

MESSAGE e007(zmco_costs_estimate) WITH p_sname p_class.

WHEN 2.

MESSAGE e008(zmco_costs_estimate) WITH p_sname p_class.

ENDCASE.

ENDFORM. " expand_gr

<b>You can look this program</b>

&----


*& Report ZCCGROUP_HIER *

*& *

&----


*& *

*& *

&----


REPORT ZCCGROUP_HIER.

  • GSETC type pool stores codes for differenct group classes

  • i.e. gsetc_costcenter_setclass = '0101'.

TYPE-POOLS: gsetc. "

TYPES: gseth_node_line LIKE grpobjects,

gseth_node_tab TYPE gseth_node_line OCCURS 0.

TYPES: gseth_val_line LIKE grpvalues,

gseth_val_tab TYPE gseth_val_line OCCURS 0.

TYPES: GSETH_MD_LINE LIKE GRPMDLINE,

GSETH_MD_TAB TYPE GSETH_MD_LINE OCCURS 0.

DATA: it_nodes TYPE gseth_node_tab,

it_values TYPE gseth_val_tab,

it_mdtab type gseth_md_tab,

wa_mdtab type GSETH_MD_LINE.

DATA: ld_setid TYPE sethier-setid,

ld_info LIKE grphinfo,

ld_overwrite LIKE sy-datar.

PARAMETERS: p_ksgru LIKE rksb1-ksgru,

p_burks TYPE bseg-BUKRS.

CONCATENATE gsetc_costcenter_setclass p_burks p_ksgru INTO ld_setid.

CALL FUNCTION 'K_HIERARCHY_TABLES_READ'

EXPORTING

e_class = gsetc_costcenter_setclass

"from gsetc type-pool

e_setid = ld_setid

e_kokrs = p_burks "company code

E_MANDT = sy-mandt

E_MASTER_DATA = 'XXX'

  • displays popup to confirm if a large amount of data is to be retrieved

E_STRUCTURE = 'X X0200' "displays popup to confirm

  • E_REPLACE_CLASS =

  • E_REPLACE_UNIT =

  • E_REPLACE_TABLE = ' '

  • E_REPLACE_FIELD = ' '

  • E_SUFFIX =

  • E_OLD_LINE_LEVEL = 0

  • IMPORTING

  • I_DOUBLE_CHECK =

  • I_MASTER_DATA =

TABLES

t_nodes = it_nodes

t_values = it_values

T_MASTER_DATA = it_mdtab

  • T_FORMULA =

  • T_FIELD_INFO =

  • T_NODE_LIST_OVERWRITE =

CHANGING

c_info = ld_info

c_overwrite = ld_overwrite

EXCEPTIONS

no_controlling_area = 1

no_chart_of_account = 2

different_controlling_areas = 3

different_chart_of_accounts = 4

set_not_found = 5

illegal_field_replacement = 6

illegal_table_replacement = 7

fm_raise = 8

convert_error = 9

no_overwrite_standard_hier = 10

no_bukrs_for_kokrs = 11

OTHERS = 12.

BREAK-POINT.

  • An alternative function module can be found below which

  • is slightly easier to code but there is no direct link between

  • the hier and the val tables, it is just based on there

  • index possition.

*types : begin of T_SETHIER.

  • include STRUCTURE SETHIER_CO.

*types: end of t_sethier.

*data: it_SETHIER type standard table of t_SETHIER.

*

*types : begin of T_SETVAL.

  • include STRUCTURE SETVAL_CO.

*types: end of t_SETVAL.

*data: it_SETVAL type standard table of t_SETVAL.

*CALL FUNCTION 'K_GROUP_REMOTE_READ'

  • EXPORTING

  • setclass = gsetc_costcenter_setclass "from gsetc type-pool

  • CO_AREA = 'UNIV'

    • CHRT_ACCTS =

  • groupname = p_ksgru

    • LANGUAGE =

    • IMPORTING

    • RETURN =

  • tables

  • et_sethier = it_SETHIER

  • ET_SETVAL = it_SETVAL.

Message was edited by:

Roman Kolesnikoff

Former Member
0 Kudos

Hi

Cost element groups and cost centre groups are stored in Sets. Table SETLEAF

Also check

<a href="/people/pavan.p/blog/2007/01/12/understanding-sets-in-sap-r3:///people/pavan.p/blog/2007/01/12/understanding-sets-in-sap-r3

<a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/wiki?path=/pages/viewpage.action&pageid=54779">https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/wiki?path=/pages/viewpage.action&pageid=54779</a>

Regards,

Arun