cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Business One - Java Connector

Former Member
0 Kudos

Hi All,

<br/><br/>

We have a SAP Business One Application installed on a laptop. The requirement is to be able to use the SAP Java API to update tables in the system. We are not allowed to connect directly to the database and was advised to use the API instead.

<br/><br/>

The downloaded API that we are using is "sapjco30P_6-10005324 32 bit.zip". I have included the dll file contained in this package in the WINDOWS/system32 folder. I am using Eclipse as IDE and already included the "sapjco3.jar" in the classpath.

<br/><br/>

First question: Am I using the right Java Connector for SAP Business One?

<br/><br/>

I got sample code on how to connect using JCO:

<br/><br/>

package sample;<br/><br/>

import java.io.File;<br/>

import java.io.FileOutputStream;<br/>

import java.util.Properties;<br/>

import java.util.concurrent.CountDownLatch;<br/><br/>

import com.sap.conn.jco.AbapException;<br/>

import com.sap.conn.jco.JCoContext;<br/>

import com.sap.conn.jco.JCoDestination;<br/>

import com.sap.conn.jco.JCoDestinationManager;<br/>

import com.sap.conn.jco.JCoException;<br/>

import com.sap.conn.jco.JCoField;<br/>

import com.sap.conn.jco.JCoFunction;<br/>

import com.sap.conn.jco.JCoFunctionTemplate;<br/>

import com.sap.conn.jco.JCoStructure;<br/>

import com.sap.conn.jco.JCoTable;<br/>

import com.sap.conn.jco.ext.DestinationDataProvider;<br/><br/>

public class StepByStepClient<br/>

{<br/>

static String ABAP_AS = "ABAP_AS_WITHOUT_POOL";<br/>

static String ABAP_AS_POOLED = "ABAP_AS_WITH_POOL";<br/>

static String ABAP_MS = "ABAP_MS_WITHOUT_POOL";<br/>

static<br/>

{<br/>

Properties connectProperties = new Properties();<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "localhost");<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "06");<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "000");<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_USER, "manager"); //sapuser<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "manager"); //sap1234<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");<br/>

createDataFile(ABAP_AS, "jcoDestination", connectProperties);<br/><br/>

connectProperties.setProperty(DestinationDataProvider.JCO_POOL_CAPACITY, "3");<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_PEAK_LIMIT, "10");<br/>

createDataFile(ABAP_AS_POOLED, "jcoDestination", connectProperties);<br/><br/>

connectProperties.clear();<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_MSHOST, "localhost");<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_R3NAME, "SID");<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "000");<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_USER, "manager"); //sapuser<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "manager"); //sap1234<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_GROUP, "GROUP");<br/>

connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");<br/>

createDataFile(ABAP_MS, "jcoDestination", connectProperties);<br/>

}<br/><br/>

static void createDataFile(String name, String suffix, Properties properties)<br/>

{<br/>

File cfg = new File(name"."suffix);<br/>

if(!cfg.exists())<br/>

{<br/>

try<br/>

{<br/>

FileOutputStream fos = new FileOutputStream(cfg, false);<br/>

properties.store(fos, "for tests only !");<br/>

fos.close();<br/>

}<br/>

catch (Exception e)<br/>

{<br/>

throw new RuntimeException("Unable to create the destination file " + cfg.getName(), e);<br/>

}<br/>

}<br/>

}<br/><br/>

public static void step1Connect() throws JCoException<br/>

{<br/>

JCoDestination destination = JCoDestinationManager.getDestination(ABAP_AS);<br/>

System.out.println("Attributes:");<br/>

System.out.println(destination.getAttributes());<br/>

System.out.println();<br/><br/>

destination = JCoDestinationManager.getDestination(ABAP_MS);<br/>

System.out.println("Attributes:");<br/>

System.out.println(destination.getAttributes());<br/>

System.out.println();<br/>

}<br/><br/>

public static void main(String[] args) throws JCoException<br/>

{<br/>

step1Connect();<br/>

}<br/>

}<br/>

<br/><br/>

Each time I run the application I run into an error:

<br/><br/>

Attributes:<br/>

Exception in thread "main" com.sap.conn.jco.JCoException: (102) JCO_ERROR_COMMUNICATION: Connect to SAP gateway failed<br/>

Connection parameters: TYPE=A DEST=ABAP_AS_WITHOUT_POOL ASHOST=localhost SYSNR=06 PCS=1<br/><br/>

LOCATION CPIC (TCP/IP) on local host with Unicode<br/>

ERROR connection to partner '127.0.0.1:3306' broken<br/>

TIME Mon May 09 10:46:46 2011<br/>

RELEASE 720<br/>

COMPONENT NI (network interface)<br/>

VERSION 40<br/>

RC -6<br/>

MODULE gwxx.c<br/>

LINE 646<br/>

DETAIL NiIRead: P=127.0.0.1:3306; L=0.0.0.0:50496<br/>

SYSTEM CALL GwRead<br/>

ERRNO 10054<br/>

ERRNO TEXT WSAECONNRESET: Connection reset by peer<br/>

COUNTER 2<br/><br/>

at com.sap.conn.jco.rt.MiddlewareJavaRfc.generateJCoException(MiddlewareJavaRfc.java:662)<br/>

at com.sap.conn.jco.rt.MiddlewareJavaRfc$JavaRfcClient.connect(MiddlewareJavaRfc.java:1362)<br/>

at com.sap.conn.jco.rt.ClientConnection.connect(ClientConnection.java:721)<br/>

at com.sap.conn.jco.rt.PoolingFactory.init(PoolingFactory.java:103)<br/>

at com.sap.conn.jco.rt.ConnectionManager.createFactory(ConnectionManager.java:293)<br/>

at com.sap.conn.jco.rt.DefaultConnectionManager.createFactory(DefaultConnectionManager.java:46)<br/>

at com.sap.conn.jco.rt.ConnectionManager.getFactory(ConnectionManager.java:262)<br/>

at com.sap.conn.jco.rt.RfcDestination.initialize(RfcDestination.java:509)<br/>

at com.sap.conn.jco.rt.RfcDestination.getAttributes(RfcDestination.java:347)<br/>

at com.sap.conn.jco.rt.RfcDestination.getAttributes(RfcDestination.java:27)<br/>

at sample.StepByStepClient.step1Connect(StepByStepClient.java:74)<br/>

at sample.StepByStepClient.main(StepByStepClient.java:304)<br/>

Caused by: RfcException: [null]<br/>

message: Connect to SAP gateway failed<br/>

Connection parameters: TYPE=A DEST=ABAP_AS_WITHOUT_POOL ASHOST=localhost SYSNR=06 PCS=1<br/>

<br/><br/>

Second question: What seems to be the problem with my sample application? Do I need to use a different Java Connector for SAP Business One or SAP Business One does not support Java Connector?

<br/><br/>

Please help.

<br/><br/>

Thank you all.

Edited by: kevinroy on May 9, 2011 4:51 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

you need a differnent jco !

Former Member
0 Kudos

Hi Yanming Zhu,<br/>

Thank you for the reply. Would you know what JCO I need to use? And where can I download it?<br/>

Thank you.

Former Member
0 Kudos

This JCO is for R/3 as far as I can see.

The JCO for Business One is contained in the SDK. You can install the B1 SDK from any B1 patch or installer, under a subfolder called Packages\SDK. There is also a helpfile (contained in C:\Program Files\SAP\SAP Business One SDK\Help\JCO.zip) included with it which gives some examples on how to use it.

Former Member
0 Kudos

Hi njmog1,<br/>

I found the JCO.zip file you were referring. I unzipped the file and there were only Java Documentation and no example on how to connect using it. <br/>

Does this mean that the JCO that I need to use for Business One are in the jar files "sboapi.jar" and "sbowrapper.jar"?<br/>

There were sample codes inside the "C:\Program Files\SAP\SAP Business One SDK\Samples\COM UI DI" but for CSharp and VB .NET only. <br/>

Have you tried using JCO with Business One before? Can you provide me with a link to the sample codes?<br/>

Thank you very much.

Former Member
0 Kudos

Unfortunately no, I have never used it but I think if you trawl through this forum, you will find some samples.

e.g. this thread shows how to make connection to the company object:

this one shows adding a document:

You will need to piece it together from forum posts & your own trial and error - the JCO is poorly documented.

And yes those are the JCO files (or whatever files you find under C:\Program Files\SAP\SAP Business One\DI API\JCO\LIB)

Former Member
0 Kudos

Hi,<br/>

Thank you very much for the reply. I am now able to move forward with what I am doing.<br/>

I used the following code in connecting but am encountering an error:<br/>

public class ConnectSAP {

// company interface

public ICompany company;

private SBOErrorMessage errMsg = null;

public static void main(String[] args) {

ConnectSAP company = new ConnectSAP();

company.conn();

}

//method make connection andinitialize company instance

public int conn() {

int rc = 0;

try {

company = SBOCOMUtil.newCompany();

company.setServer("192.168.0.216"); //192.168.0.216

company.setCompanyDB("SBODemoUS");

company.setUserName("manager");

company.setPassword("manager");

company.setDbServerType(SBOCOMConstants.BoDataServerTypes_dst_MSSQL2005);

company.setUseTrusted(new Boolean(false));

company.setLanguage(SBOCOMConstants.BoSuppLangs_ln_English);

company.setDbUserName("username");

company.setDbPassword("password");

//company.setAddonIdentifier("...");

//company.setLicenseServer("...");

rc = company.connect();

if (rc == 0) {

System.out.println("Connected!");

} else {

errMsg = company.getLastError();

System.out.println(

"I cannot connect to database server: "

+ errMsg.getErrorMessage()

+ " "

+ errMsg.getErrorCode());

}

} catch (Exception e) {

e.printStackTrace();

return -1;

}

return rc;

}

public void freeConnection(){

company.disconnect();

}

}<br/>

I am getting the error "Failed to Connect to SBOCommon -111".<br/>

Error is still the same even if I set UseTrusted to true and comment the DbUserName and DbPassword.<br/>

Do I need to specify the license? Or login to SAP before connecting?<br/>

Thank you.

Former Member
0 Kudos

"Failed to connect to SBO-COMMON" error means your application can not connect to the database server.

To connect it needs server name, server type, username/password or usetrusted=true.

First thing to check - is SQL native client installed on your machine?

If it is:

Have you tried with server name instead of IP address?

Are you using SQL2005, or by any chance SQL2008?

Can you ping the sql server from your machine?

Try specifying the license server as "SERVERNAME:30000".

Former Member
0 Kudos

Hi,<br/>

Thank you very much for the very informative replies. I am now able to connect to SAP Business One. What I was missing was in the server, needed to add the database instance in the server parameter like this "LENOVO-PC
SQLEXPRESS".<br/>

You have been very helpful.<br/>

Thank you very much.

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Kevinroy,

Refer This....

link: [url]

Link: [url]

Link: [url]

Thanks

Shafi