The SAP DI API (Data Interface API) is part of the SAP Business One Software Development Kit (SDK) that allows developers to interact with the database. The API exposes objects and methods that can be used to read, write, update and delete data. The API is COM based, so there are .Net and Java interfaces.
The SDK and supporting files are provided with SAP Business One. This article focuses on a simple .Net console application that will list all companies setup in Business One. First ensure that you have located the following DLL file SAPbobsCOM90.dll. You will need to add a refernce to this DDL in your .Net project.
Open Visual Studios and create a new Console Application. From the Project menu click Add Reference. Browse for SAPbobsCOM90.dll.
The API requires authentication, which means you will first need to login to a company.
1SAPbobsCOM.Company comp = new SAPbobsCOM.Company();
Listing 1 above shows the authentication and connection code. Notice that the DbServerType is set to HANADB. If you are using MSSQL, you will need to change the server type to dst_MSSQL*.
Errors are handled by the GetLastError() method of the Company object. This method accpets two paramaters, which must be passed by reference. The first argument is errCode, which must be of type int and the second is errMsg which must be of type string.
1int errCode = 0;
2string errMsg = "";
4comp.GetLastError(out errCode, out errMsg);
6if (errCode < 0)
If errCode is below 0, this means an error has occured. You should then check errMsg to determine what the error was. If errCode is 0 then no error occured.
If the connection was successful, you can then call the GetCompanyList() method on the comp object to get a Recordset containing all companies.
1SAPbobsCOM.Recordset result = comp.GetCompanyList();