on 08-23-2005 12:04 PM
Hi,
I am getting error message while running JCo java code. I followed the given steps in the installation guide. I know i did something wrong in this.
I created a folder C:\JCO and unzipped the downloaded JCo files librfc32.dll, sapjcorfc.dll and sapjco.jar.
Copied the file librfc32.dll from C:\JCO directory to C:\WINNT\SYSTEM32
Added the path c:\JCO\sapjco.jar; in the environmental variables. [I followed the following --> Right Click on My Computer --> Properties --> Advanced --> Environment Variables --> Edited the existing path and added with java path like C:\j2sdk1.4.2_05\bin;c:\JCO\sapjco.jar;].
After this I am trying to execute the following code. It is copiling without any problem and giving error message while run mode.
C:\JCO>java Bapi1
Exception in thread "main" java.lang.NoClassDefFoundError: com/sap/mw/jco/JCO$Structure
******java code*****
import com.sap.mw.jco.*;
public class Bapi1 extends Object {
JCO.Client mConnection;
JCO.Repository mRepository;
public Bapi1() {
try {
// Change the logon information to your own system/user
mConnection =
JCO.createClient("020", // SAP client
"myuserid", // userid
"****", // password
"EN", // language
"myerp server host name", // application server host name
"00"); // system number
mConnection.connect();
mRepository = new JCO.Repository("SAPJCo", mConnection);
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
JCO.Function function = null;
JCO.Table codes = null;
try {
function = this.createFunction("BAPI_COMPANYCODE_GETLIST");
if (function == null) {
System.out.println("BAPI_COMPANYCODE_GETLIST" +
" not found in SAP.");
System.exit(1);
}
mConnection.execute(function);
JCO.Structure returnStructure =
function.getExportParameterList().getStructure("RETURN");
if (! (returnStructure.getString("TYPE").equals("") ||
returnStructure.getString("TYPE").equals("S")) ) {
System.out.println(returnStructure.getString("MESSAGE"));
System.exit(1);
}
codes =
function.getTableParameterList().getTable("COMPANYCODE_LIST");
for (int i = 0; i < codes.getNumRows(); i++) {
codes.setRow(i);
System.out.println(codes.getString("COMP_CODE") + '\t' +
codes.getString("COMP_NAME"));
}
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
try {
codes.firstRow();
for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) {
function = this.createFunction("BAPI_COMPANYCODE_GETDETAIL");
if (function == null) {
System.out.println("BAPI_COMPANYCODE_GETDETAIL" +
" not found in SAP.");
System.exit(1);
}
function.getImportParameterList().
setValue(codes.getString("COMP_CODE"), "COMPANYCODEID");
function.getExportParameterList().
setActive(false, "COMPANYCODE_ADDRESS");
mConnection.execute(function);
JCO.Structure returnStructure =
function.getExportParameterList().getStructure("RETURN");
if (! (returnStructure.getString("TYPE").equals("") ||
returnStructure.getString("TYPE").equals("S") ||
returnStructure.getString("TYPE").equals("W")) ) {
System.out.println(returnStructure.getString("MESSAGE"));
}
JCO.Structure detail =
function.getExportParameterList().
getStructure("COMPANYCODE_DETAIL");
System.out.println(detail.getString("COMP_CODE") + '\t' +
detail.getString("COUNTRY") + '\t' +
detail.getString("CITY"));
}
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
mConnection.disconnect();
}
public JCO.Function createFunction(String name) throws Exception {
try {
IFunctionTemplate ft =
mRepository.getFunctionTemplate(name.toUpperCase());
if (ft == null)
return null;
return ft.getFunction();
}
catch (Exception ex) {
throw new Exception("Problem retrieving JCO.Function object.");
}
}
public static void main (String args[]) {
Bapi1 app = new Bapi1();
}
}
Hi Venu,
You have to add the java library sapjco.jar to the java classpath instead of the system classpath. You can do this by adding the -cp or -classpath parameter to your java call. So then you would get:
java -classpath C:JCOsapjco.jar Bapi1
Hope this helps,
Johan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
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.