on 10-30-2006 8:59 AM
Hi,
I call my BAPI from java client. If i use only one connection all is ok, but when i use connection pool i receive one exception.
Where is error?
sorry for bad english,
thanks
this is stack trace
[code]
java.lang.Exception: Problem retrieving JCO.Function object.
at TestBAPIJava.main(TestBAPIJava.java:71)
Caused by: java.lang.NullPointerException
at com.sap.mw.jco.JCO$Client.connect(JCO.java:3108)
at com.sap.mw.jco.JCO$Repository.getRepositoryClient(JCO.java:19331)
at com.sap.mw.jco.JCO$Repository.queryStructureDefinition(JCO.java:19420)
at com.sap.mw.jco.JCO$Repository.getStructureDefinition(JCO.java:19570)
at com.sap.mw.jco.JCO$BasicRepository.getFunctionTemplate(JCO.java:18566)
at TestBAPIJava.main(TestBAPIJava.java:65)
[/code]
and this is sample code
[code]
import com.sap.mw.jco.*;
public class TestBAPIJava {
static String connectionPoolTest = "testPool";
static String sapclient = "100";
static String userId = "test";
static String psw = "test";
static String iphost = "000.000.000.000";
static String sysnr = "00";
private static JCO.Client login(boolean usePool) {
JCO.Client connection = null;
if (usePool) {
JCO.Pool pool = JCO.getClientPoolManager().getPool(connectionPoolTest);
if (pool == null) {
System.out.println("createPool");
JCO.addClientPool(connectionPoolTest, 5,
sapclient, userId, psw,
null, iphost, sysnr);
}
connection = JCO.getClient(connectionPoolTest);
} else {
connection = JCO.createClient(sapclient, userId, psw,
null, iphost, sysnr);
connection.connect();
}
System.out.println("Connection attribute " + connection.getAttributes());
return connection;
}
private static void logout(JCO.Client connection, boolean usePool) {
if (usePool) {
JCO.releaseClient(connection);
} else {
connection.disconnect();
}
}
public static void main(String args[]) {
JCO.Client connection = null;
JCO.Repository mRepository = null;
JCO.Function fun = null;
String nameFun = "BAPITEST";
<b>
// if true all ok else exception
boolean usePool = true;
</b>
try {
connection = login(usePool);
System.out.println("connessione aperta "
+ connection.getAttributes());
mRepository = new JCO.Repository("TestRepository", connection);
System.out.println("mRepository " + mRepository);
try {
IFunctionTemplate ft =
<b>// error point </b>
mRepository.getFunctionTemplate(nameFun);
if (ft == null)
throw new Exception("Problem retrieving JCO.Function object.");
fun = ft.getFunction();
} catch (Exception ex) {
throw new Exception("Problem retrieving JCO.Function object.", ex);
}
fun.getImportParameterList().setValue("0001", "PARAM");
connection.execute(fun);
JCO.ParameterList expParam = fun.getExportParameterList();
JCO.Structure returnStructure = expParam.getStructure("RETURN");
for (int i = 0; i < returnStructure.getNumFields(); i++) {
System.out.println(returnStructure.getName(i) + ":" + returnStructure.getValue(i));
}
System.out.println("all ok");
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (connection != null) {
System.out.println("connessione chiusa");
logout(connection, usePool);
}
}
}
}
[/code]
Hi everybody
I am having exactly the same problem while using a connection pool and trying to call a function, with a direct connection I do get the function, but with a connection pull I get null and then a nullpointerException
Does anybody know what the problem could be?
Regards and thanks in advance
Gino
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Everybody,
Luca, I just found a code that helped me get run a BAPI using Connection Pools,
you can get the code in this URL:
http://www.persistentsys.com/presentation/Java_SAP_Integration.pdf
Good Luck and regards
Gino
Hi,
thanks for your most useful link.
the bad statement is this
mRepository = new JCO.Repository("TestRepository", connection);
and right statement is
mRepository = new JCO.Repository("TestRepository", connectionPoolTest);
with Connection Pool, the repository costructor to use is
<i>JCO.Repository(java.lang.String name, java.lang.String pool_name) </i>
and not is
<i>JCO.Repository(java.lang.String name, JCO.Client client) </i>
I had to read the API documentation more carefully
Thanks,
Luca
I think this problem is caused by the JCo 2.1.7.
Please test by the JCo 2.1.6 and report the result.
Thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
The Reason for the error is There is no functional module with the name "BAPITEST" in the R/3.
Please give the existing BAPI name in the
String nameFun = "BAPITEST";
Kind Regards
Mukesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
78 | |
10 | |
7 | |
6 | |
6 | |
6 | |
6 | |
6 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.