Use the following tables
SETHEADER (Set Header and Directory)
setheadert (get desc)
eg:
select single * from setheadert
where langu = 'E'
and setclass = '0101'
and subclass = 'PET1'
and setname = p_ccgrp.
SETLEAF (Values in Sets)
setnode
Function modules that can be used:
K_HIERARCHY_TABLES_READ
FM: K_GROUP_SELECT
CALL FUNCTION 'K_GROUP_SELECT'
EXPORTING
* BUTTONS = 'X'
CLASS = '0101'
* CRUSER = '*'
FIELD_NAME = 'KOSTL'
SEARCHFLD = 'PET1'
SEARCHFLD_INPUT = 'X'
SEARCHFLD_REQUIRED = 'X'
* SET = '*'
* START_COLUMN = 10
* START_ROW = 5
TABLE = 'CCSS'
TYPELIST = 'BS'
UPDUSER = '*'
* KOKRS =
* KTOPL =
IMPORTING
* CLASS_NAME =
SET_NAME = P_CCGRP
* SET_TITLE =
* TABLE_NAME =
* SETID =
EXCEPTIONS
NO_SET_PICKED = 1
OTHERS = 2.
G_SET_GET_ID_FROM_NAME
G_SET_TREE_IMPORT
G_SET_TREE_ADD_POINTERS
For cost centers use '0102' as SETCLASS.
DATA: SETID LIKE SETHIER-SETID,
SET_INFO LIKE SETINFO,
SET_HIERARCHY LIKE SETHIER OCCURS 0 WITH HEADER LINE,
SET_VALUES LIKE SETVALUES OCCURS 0 WITH HEADER LINE,
SET_HIER_PTR LIKE SETHIERPTR OCCURS 0 WITH HEADER LINE,
SET_VAL_PTR LIKE SETVALPTR OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'G_SET_GET_ID_FROM_NAME'
EXPORTING
SETCLASS = '0102'
KTOPL = '' <-- put your value here
KOKRS = '' <-- put your value here
IMPORTING
NEW_SETID = SETID
SET_INFO = SET_INFO.
CALL FUNCTION 'G_SET_TREE_IMPORT'
EXPORTING
SETID = SETID
TABLES
SET_HIERARCHY = SET_HIERARCHY
SET_VALUES = SET_VALUES.
CALL FUNCTION 'G_SET_TREE_ADD_POINTERS'
TABLES
SET_HIERARCHY = SET_HIERARCHY
SET_VALUES = SET_VALUES
SET_HIER_PTR = SET_HIER_PTR
SET_VAL_PTR = SET_VAL_PTR.
Example program get cost center hierarchy:
* to get cost centers belong to the selected cost center group.
FORM APPEND_COST_CENTER.
SELECT SETNAME SUBSETNAME
INTO TABLE T_COSTCTR
FROM SETNODE
WHERE SETCLASS EQ '0101' " 0101 = cost center group
AND SUBCLASS EQ 'PET1' " PET1 = controlling area
AND SETNAME EQ P_CCGRP " cost center group value
AND SUBSETCLS EQ '0101'
AND SUBSETSCLS EQ 'PET1'.
LOOP AT T_COSTCTR.
SELECT SETNAME SUBSETNAME
INTO CORRESPONDING FIELDS OF T_COSTCTR
FROM SETNODE
WHERE SETCLASS EQ '0101'
AND SUBCLASS EQ 'PET1'
AND SETNAME EQ T_COSTCTR-SUBSETNAME
AND SUBSETCLS EQ '0101'
AND SUBSETSCLS EQ 'PET1'.
APPEND T_COSTCTR.
ENDSELECT.
ENDLOOP.
LOOP AT T_COSTCTR.
SELECT VALSIGN VALOPTION VALFROM VALTO
INTO (S_CCTR-SIGN, S_CCTR-OPTION,
S_CCTR-LOW, S_CCTR-HIGH)
FROM SETLEAF
WHERE SETCLASS EQ '0101'
AND SUBCLASS EQ 'PET1'
AND SETNAME EQ T_COSTCTR-SUBSETNAME.
APPEND S_CCTR.
ENDSELECT.
ENDLOOP.
* For cost center group that is NOT in std hierachy
SELECT VALSIGN VALOPTION VALFROM VALTO
INTO (S_CCTR-SIGN, S_CCTR-OPTION,
S_CCTR-LOW, S_CCTR-HIGH)
FROM SETLEAF
WHERE SETCLASS EQ '0101'
AND SUBCLASS EQ 'PET1'
AND SETNAME EQ P_CCGRP.
APPEND S_CCTR.
ENDSELECT.
ENDFORM.
No comments:
Post a Comment