HI Campers (I really want to say band campers ;) )
Hope everyone is well! Here's my tip.
I can't count how many times I've been showing financial master data examples, and someone asks me: "What about hierarchies?" The first time, I didn't know. For cost centers - which is my example - you can assign a standard hierarchy in KS01/2, but you cannot assign the cost center to other groups. I looked at the tcode for cost centers hierarchies (groups), KSH1/2 and cringed a little. I always try to avoid GUI scripting, so I kept looking There are BAPIs to help, and to get a list of nodes in a hierarchy, a bapi is best. But to add/remove nodes and add/remove cost centers easily, I had to get creative.
So my tip - there's an accessibility format that will help automate KSH1/2, and I can thank a colleague for that tip. Note, too, that this will work for profit center hierarchies, as well, KCH1/2.
Here's what a cost center hierarchy looks like normally:

- Here's how to swap into accessibility format:
- On the first screen of KSH2, for example, click Extras -> Default Settings -> Format, like this
-
- Check accessibility and save user parameters
-
Now the hierarchy will look like this for a particular node in a cost center group.
The button on top will list cost centers. And there are add and delete buttons for the group nodes.
Here is a list of Cost Centers on that particular node - and notice the add and delete buttons for the cost centers assigned to that group node
- create an accessibility format script that changes the format and pass in the "X" to check the accessibility option and save to user parameters
- create a script to add nodes or delete nodes and separate scripts to add or delete cost centers. For these scripts:
- You'll need to pass in the parent node and then a child node to add or delete nodes in the group
- You'll also need to pass the parent node and then cost centers to add or delete
- then run the accessibility format script to un-check accessibility mode - pass in a blank
- chain them together so that it swaps the format, runs the hierarchy updates then swaps the format back.
Note that if you choose to use GUI scripting, you can do all of these steps in one script.
One additional tip - if you delete a node, all nodes and cost centers assigned to those nodes will also be deleted from the cost center group, so please take care with this action.
If you have additional suggestions here on this topic, please reply. There are often many ways to approach an automation challenge.
Happy scripting!
Sigrid
PS: I have an example if anyone needs it that moves cost centers from one group node to another. I've submitted it as a template, so hopefully it will be available soon.
------------------------------
Sigrid Kok
PSE | Winshuttle NA
------------------------------