cancel
Showing results for 
Search instead for 
Did you mean: 

BAPI function call in Java

Former Member
0 Kudos

Hi,

I am trying to make BAPI function call in JAVA. I am using the following libraries for IBM AIX version and the sapjco.jar

1) librfccm.o

2) libsapjcorfc.so

The above 2 libraries are in my java lib path.

But I get a exception and it is referring to sapjcorfc.dll (which is a windows version) instead of referring to libsapjcorfc.so

What should I do so that it refers to libsapjcorfc.so and not sapjcorfc.dll

Error Details: java.lang.ExceptionInInitializerError: JCO.classInitialize():

Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'

JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc

[sapjcorfc (A file or directory in the path name does not exist.)]. java.library.path

[/usr/java14_64/jre/bin:/usr/java14_64/jre/bin:/usr/java14_64/jre/bin/classic:/usr/java14_64/jre/bin:

/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:

/tmp/sapinst_exe.1081378.1199455057:/usr/sap/DP0/SYS/exe/run:/home/db2inst1/sqllib/lib64:

/usr/sap/DP0/DVEBMGS42/exe::/usr/lib:/usr/sap/DP0/DVEBMGS42/j2ee/os_libs:/usr/sap/DP0/DVEBMGS42/exe:

/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:/usr/lib:/lib:/usr/sap/DP0/SYS/exe/run:

/home/db2inst1/sqllib/lib64]

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Looks like you're using JCo 2.x. For AIX the installation instructions indicate that the JCo installation directory (where the dynamic link libraries reside) has to be added to the environment variable LIBPATH.

Also, another cause for this problem is often using incompatible versions - 32bit versus 64bit - of libraries and JVM. E.g. not sure about AIX, but on Solaris you'd pick for example via option <i>-d64</i> the 64bit JVM. So if your library is a 64bit version, but you're running a 32bit JVM, you'd get this kind of error.

For quick test on the machine (assuming you have an X terminal), just run java along with your normal options and specify the SAP JCo jar library. This will open a window with some version information and also should produce the error that you're seeing when running your application. This way you should also see, that the problem is not related to your coding...

Cheers, harald

Former Member
0 Kudos

Harald,

We are using right version of the Jars - 64 bit AIX version. I think we have not set the LIBPATH environment variable for the application as I am not sure how to set this.

We use ant to build and have action type = update in deploy-manager-config.xml

But LIBPATH at the AD0ADM user level has the path where the dynamic link libraries reside and it is not picking from there.

But I am setting the LIBPATH variable when i run a stand alone java program from a shell script.

Jawed,

I dont have Netweaver Developer studio installed so i am not sure if the portal has any sapjco.jar by default.

Thanks,

Selvam.

Former Member
0 Kudos

Netweaver Developer studio and Netweaver Enterprise portal are two different entities. If you have Enterprise portal installed you have sapjco.jar there in the server.

Developer sudio only used for developing java and portal application you can use any other developement application you like.

Jawed

Former Member
0 Kudos

Hi All,

Thanks for all your solutions, issue is reolved.

We added an xml named application-j2ee-engine.xml in the folder META_INF of the ear file with the following contents.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE application-j2ee-engine SYSTEM 'application-j2ee-engine.dtd'>

<application-j2ee-engine>

<reference reference-type="hard">

<reference-target provider-name="engine.sap.com"

target-type="library">

com.sap.mw.jco

</reference-target>

</reference>

</application-j2ee-engine>

Answers (1)

Answers (1)

Former Member
0 Kudos

From where you are running your application?

I guess you have server installed on your IBM AIX and you are calling BAPI from another system which might have windows install, if this is the case you are getting the correct exception.

Please post your code or some technical details about the problem.

Jawed Ali

Former Member
0 Kudos

Hi Jawed,

when I try it as a stand alone java code on IBM AIX version BAPI connection works and it fetches the roles listed for an user from the ACTIVITYGROUP table.

The same piece of code bundled in an ear and when deployed in SAP netweaver portal gives different errors. My sapjco.jar is in application lib folder and it is referred in classpath

first time when i access the application url it gives me

Error Details: java.lang.ExceptionInInitializerError: JCO.classInitialize():

Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'

JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc

http://sapjcorfc (A file or directory in the path name does not exist.). java.library.path

[/usr/java14_64/jre/bin:/usr/java14_64/jre/bin:/usr/java14_64/jre/bin/classic:/usr/java14_64/jre/bin:

/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:

/tmp/sapinst_exe.1081378.1199455057:/usr/sap/DP0/SYS/exe/run:/home/db2inst1/sqllib/lib64:

/usr/sap/DP0/DVEBMGS42/exe::/usr/lib:/usr/sap/DP0/DVEBMGS42/j2ee/os_libs:/usr/sap/DP0/DVEBMGS42/exe:

/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:/usr/lib:/lib:/usr/sap/DP0/SYS/exe/run:

/home/db2inst1/sqllib/lib64]

when i acess the application url next time it gives me

Application error occurred during request processing.

Details: java.lang.NoClassDefFoundError: com.sap.mw.jco.JCO (initialization failure)

Exception id: [00145EB7604700720000000F000C20FE00047CA4F0EF0615]

Below is my my javacode - I am calling the method getUserRoles

package com.mysap.sso;

import com.sap.mw.jco.*;

import java.util.ArrayList;

import java.util.List;

public class BapiConnection {

private static JCO.Client mConnection;

private static JCO.Repository mRepository;

private static JCO.Function createFunction(String functionName)

throws Exception {

try {

IFunctionTemplate ft = mRepository.getFunctionTemplate(functionName

.toUpperCase());

if (ft == null) {

return null;

} else {

return ft.getFunction();

}

} catch (Exception ex) {

throw ex;

}

}

public List getUserRoles(String user) {

JCO.Function function = null;

JCO.Table activitygroups = null;

List rolesList = null;

mConnection = null;

mRepository = null;

mConnection = JCO.createClient("300", "INVTRY_SEGMT", "Welcome%1",

null, "ade00fe", "22");

try {

//Connect to the WebAS ABAP with the parameters above

mConnection.connect();

//Create a function repository to be able to build a function

mRepository = new JCO.Repository("INVTRY_SEGMT", mConnection);

//Get the function

function = createFunction("BAPI_USER_GET_DETAIL");

//Set the only import parameter

function.getImportParameterList().setValue(user, "USERNAME");

//Execute the function

mConnection.execute(function);

//Get the 'ADDRESS' return structure

activitygroups = function.getTableParameterList().getTable(

"ACTIVITYGROUPS");

rolesList = new ArrayList();

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

.nextRow()) {

System.out.println(activitygroups.getString("AGR_NAME"));

logger.debug(activitygroups.getString("AGR_NAME"));

rolesList.add(activitygroups.getString("AGR_NAME"));

}

mConnection.disconnect();

} catch (Exception ex) {

System.err.println(ex.toString());

}

return rolesList;

}

}

Former Member
0 Kudos

Sorry Jawed..I tried to paste the code in block mode but it looks like a paragraph.

I am not sure If I have conveyed the issue.

when I try it as a stand alone java code on IBM AIX version BAPI connection works and

it fetches the roles listed for an user from the ACTIVITYGROUP table.

The same piece of code bundled in an ear and when deployed in SAP netweaver portal gives different errors.

My sapjco.jar is in application lib folder and it is referred in classpath

first time when i access the application url it gives me

Error Details: java.lang.ExceptionInInitializerError: JCO.classInitialize():

Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'

JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc

http://sapjcorfc (A file or directory in the path name does not exist.). java.library.path

[/usr/java14_64/jre/bin:/usr/java14_64/jre/bin:/usr/java14_64/jre/bin/classic:/usr/java14_64/jre/bin:

/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:

/tmp/sapinst_exe.1081378.1199455057:/usr/sap/DP0/SYS/exe/run:/home/db2inst1/sqllib/lib64:

/usr/sap/DP0/DVEBMGS42/exe::/usr/lib:/usr/sap/DP0/DVEBMGS42/j2ee/os_libs:/usr/sap/DP0/DVEBMGS42/exe:

/usr/sap/DP0/DVEBMGS42/exe:/usr/sap/DP0/DVEBMGS42/exe:/usr/lib:/lib:/usr/sap/DP0/SYS/exe/run:

/home/db2inst1/sqllib/lib64]

Second time when I access the url i get

Application error occurred during request processing.

Details: java.lang.NoClassDefFoundError: com.sap.mw.jco.JCO (initialization failure)

Exception id: [00145EB7604700720000000F000C20FE00047CA4F0EF0615]

Below is my my javacode - I am calling the method getUserRoles

Former Member
0 Kudos

package com.mysap.sso;

import com.sap.mw.jco.*;

import java.util.ArrayList;

import java.util.List;

public class BapiConnection {

private static JCO.Client mConnection;

private static JCO.Repository mRepository;

private static JCO.Function createFunction(String functionName)

throws Exception {

try {

IFunctionTemplate ft = mRepository.getFunctionTemplate(functionName

.toUpperCase());

if (ft == null) {

return null;

} else {

return ft.getFunction();

}

} catch (Exception ex) {

throw ex;

}

}

public List getUserRoles(String user) {

JCO.Function function = null;

JCO.Table activitygroups = null;

List rolesList = null;

mConnection = null;

mRepository = null;

mConnection = JCO.createClient("300", "INVTRY_SEGMT", "Welcome%1",

null, "ade00fe", "22");

try {

//Connect to the WebAS ABAP with the parameters above

mConnection.connect();

//Create a function repository to be able to build a function

mRepository = new JCO.Repository("SKUMAR3", mConnection);

//Get the function

function = createFunction("BAPI_USER_GET_DETAIL");

//Set the only import parameter

function.getImportParameterList().setValue(user, "USERNAME");

//Execute the function

mConnection.execute(function);

//Get the 'ADDRESS' return structure

activitygroups = function.getTableParameterList().getTable(

"ACTIVITYGROUPS");

rolesList = new ArrayList();

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

.nextRow()) {

System.out.println(activitygroups.getString("AGR_NAME"));

logger.debug(activitygroups.getString("AGR_NAME"));

rolesList.add(activitygroups.getString("AGR_NAME"));

}

mConnection.disconnect();

} catch (Exception ex) {

System.err.println(ex.toString());

}

return rolesList;

}

}

Former Member
0 Kudos

Netweaver portal already have the sapjco.jar, so you do not required to deploy with your archive; just add into your class path to resolve the compile time errors and Netweaver Developer studio provides sapjco.jar. check following location:

<Installtion Path>SAP/IDE/IDE70/eclipse/plugins/com.sap.mw.jco_2.0.0/lib/sapjco.jar

I don't see any error in your code just that jar file you are bundling with your application. It might be conflicting with the server's jar file. try deploy your project without the jar file. I didn't face such issue, I had developer machine with windows and server on linux.

Jawed Ali