cancel
Showing results for 
Search instead for 
Did you mean: 

Read BAPI from java

Former Member
0 Kudos

Hi All,

I had a requirement of reading values from BAPI through Java. Can anybody give me links or documents on how to connect to R/3 system from java. I know this can be done through JCO API or JCA API, but i could not find enough supportive documents in SDN. So please help me out.

Regards

Raghu

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Dear RAghu

Use sapjco.jar file to use this code

Regards

Noel

PuneetSaxena
Contributor
0 Kudos

Hi Noel,

This is perfect. Thanks a lot for the solution.

Regards

Puneet

Former Member
0 Kudos

Dear Raghu

You can read the BAPI values using JCO objects and I providing you wiht the sample code for the same

public class BapiClass {

static JCO.Client R3Client=null;

IRepository R3repository=null;

JCO.Function function=null;

JCO.Table dataTable=null;

String client = "040";

String login = "developer";

String pass = "sappmcoe1";

String language = "en";

String hostname = "hostname";

String system = "00";

String rfcException=null;

String loginId=null;

// Variables for BAPI Vaues

String DLCode=null;

String Status=null;

String Icon=null;

String ToolTip=null;

Alerts alert;

ArrayList dataList = new ArrayList();

ArrayList errorList= new ArrayList();

Iterator alertsIter=null;

Iterator errorIter=null;

public BapiClass(){

}

public void setLoginId(String loginId) {

this.loginId = loginId;

}

public Iterator getAlertsIterator(){

return alertsIter;

}

public String getAlerts()

{

int row=0;

rfcException = "No Exception";

try {

//Creating Connection

R3Client = JCO.createClient(

client,

login,

pass,

language,

hostname,

system);

R3repository = JCO.createRepository("MyRepository", R3Client);

}catch (Exception e)

{

rfcException = "<b>Error connecting to database system</b><BR>"+e.toString();

return rfcException;

}

try{

//Invoking BAPI

IFunctionTemplate ftemplate =R3repository.getFunctionTemplate("ZSE_GETALERTS_NEW");

function = new JCO.Function(ftemplate);

JCO.ParameterList input=function.getImportParameterList();

//input.setValue(loginId,"I_USERID");

input.setValue(loginId,"I_USERID");

R3Client.execute(function);

//E_ALERTS is the BAPI Output Table Name

dataTable = function.getExportParameterList().getTable("E_ALERTS");

row = dataTable.getNumRows();

for (int i = 0; i < dataTable.getNumRows(); i++)

{

dataTable.setRow(i);

DLCode = dataTable.getString("DLCODE");

Status=dataTable.getString("STATUS");

Icon = dataTable.getString("ICON");

ToolTip=dataTable.getString("TOOLTIP");

alert=new Alerts(DLCode,Status,Icon,ToolTip);

dataList.add(i, alert);

}

alertsIter = dataList.iterator();

}

catch (Exception ex) {

ex.getStackTrace();

rfcException = "<b>Error connecting to database system</b><BR>"+ex.toString();

return rfcException;

}

return rfcException;

}

}

Regards

Noel

Former Member
0 Kudos

Hi buddy,

I have tried your piece of code for calling the BAPI through JAVA. But i am facing few problems in that code. What are the import statements i need to declare in this piece of code.I have set the CLASSPATH for SAPJCO.jar. I am facing error like JCO class does not exist. Kindly help me out with this problem. Plz provide me the import statement for JCO.

I have used this import statement which i found somewhere but it is of no use for me.Throwing error

import com.sap.mw.jco.*;

Kindly help me out of this issue.

Thanks in advance

Amit

Former Member
0 Kudos

Amit, JCO 2.0 is the answer. With the 3.1 JCo you have new includes and setting up a connection is different.

You may have to use

import com.sap.conn.jco.JCoDestination;

import com.sap.conn.jco.JCoDestinationManager;

import com.sap.conn.jco.ext.DestinationDataEventListener;

import com.sap.conn.jco.ext.DestinationDataProvider;

appropriately. A little bit of research is required.