This sample shows how to build a treeview with cost centers of one selected standard hierarchy.
About
Cost center hierarchies are stored in different tables in SAP. Every controlling area has one standard hierarchy defined. Cost centers belong to these standard hierarchies.
Set Up a Treeview of Cost Centers
The Windows form for the treeview should contain following elements:
One button: btnGetCC
One DataGridView: dgContArea
One TreeView: tvCC
Follow the steps below to build a treeview during FormLoad:
Connect to the SAP system using R3Connection.
Read the SAP table TKA01 that contains the controlling area standard hierarchy relations.
Display the table in a DataGridView.
When selecting a controlling area with a click in the DataGridView, the standard hierarchy is written into a variable.
When clicking the button, the structure of the cost centers and the hierarchy are build and shown in the treeview.
usingSystem;usingERPConnect;// Set your ERPConnect licenseLIC.SetLic("xxxx");usingvarconnection=newR3Connection(host:"server.acme.org",systemNumber:00,userName:"user",password:"passwd",language:"EN",client:"001"){Protocol=ClientProtocol.NWRFC,};connection.Open();stringKOKRS;stringSTDHIER;privatevoidfrmMain_Load(objectsender,EventArgse){try{connection.AskUserAndOpen(true);ReadTabletable=newReadTable(connection);table.AddField("KOKRS");table.AddField("BEZEI");table.AddField("KHINR");table.TableName="TKA01";table.Run();DataTableresulttable=table.Result;dgContArea.DataSource=resulttable;dgContArea.Columns["KOKRS"].HeaderText="Controlling Area";dgContArea.Columns["BEZEI"].HeaderText="Name";dgContArea.Columns["KHINR"].HeaderText="Std. Hierarchy";dgContArea.Columns["KOKRS"].Width=120;dgContArea.Columns["BEZEI"].Width=150;}catch(Exceptione1){MessageBox.Show(e1.Message);}}