on 05-04-2009 10:57 AM
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
Dear RAghu
Use sapjco.jar file to use this code
Regards
Noel
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.