Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Calling BAPI via Jco 3.0

Hi all,

I wrote a simple program that uses jco 3.0 to call a BAPI on R/3 4.6c. I followed the example at http://www.vogella.de/articles/SAPJCo/article.html and replaced the BAPI to BAPI_USER_GET_DETAIL since i dont have the one in the article in my system.

I get a NullPointerException when calling the function. Below is the exception trace + code, any help is appreciated.

The happens at JCoFunction function = connect.getFunction("BAPI_USER_GET_DETAIL");

SORRY THE MARKUP DOES NOT SEEM TO WORK...

public class JcoTester {

static String SAP = "SAP_SERVER";

public static void main(String[] args) {

//SAP System

SapSystem system = new SapSystem();

system.setClient("220");

system.setHost("myservername");

system.setLanguage("en");

system.setSysID("00");

system.setUser("myuserID");

system.setPassword("mypassword");

Connection connect = new Connection(system);

JCoFunction function = connect.getFunction("BAPI_USER_GET_DETAIL");

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

connect.execute(function);

JCoTable table = function.getTableParameterList().getTable("PARAMETER");

System.out.println(table.isEmpty());

TableAdapterReader tableAdapter = new TableAdapterReader(table);

System.out.println("Number of parameters: " + tableAdapter.size());

System.out.println("parameter ID" + " " + "Parameter value");

for (int i = 0; i < tableAdapter.size(); i++){

System.out.println(tableAdapter.get("PARID") + " " + tableAdapter.get("PARVA"));

tableAdapter.next();

}

}

}

public class Connection {

static String SAP_SERVER = "SAP_SERVER";

private JCoRepository repos;

private JCoDestination dest;

private final Properties properties;

public Connection(SapSystem system){

properties = new Properties();

properties.setProperty(DestinationDataProvider.JCO_ASHOST, system.getHost());

properties.setProperty(DestinationDataProvider.JCO_SYSNR, system.getSysID());

properties.setProperty(DestinationDataProvider.JCO_CLIENT, system.getClient());

properties.setProperty(DestinationDataProvider.JCO_PASSWD, system.getPassword());

properties.setProperty(DestinationDataProvider.JCO_USER, system.getUser());

properties.setProperty(DestinationDataProvider.JCO_LANG, system.getLanguage());

MyDestinationDataProvider myProvider = new MyDestinationDataProvider();

myProvider.changePropertiesForABAP_AS(properties);

com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProvider);

try{

dest = JCoDestinationManager.getDestination("SAP_SERVER");

System.out.println("Attributes:");

System.out.println(dest.getAttributes());

System.out.println();

}catch(JCoException e){

throw new RuntimeException(e);

}

}

public JCoFunction getFunction(String functionStr){

JCoFunction function = null;

try{

function = repos.getFunction(functionStr);

}catch (Exception e){

e.printStackTrace();

throw new RuntimeException("Problem retrieving JCO.Function object.");

}

if (function == null){

throw new RuntimeException("Not possible to receive function.");

}

return function;

}

public void execute(JCoFunction function){

try{

JCoContext.begin(dest);

function.execute(dest);

JCoContext.end(dest);

}catch (JCoException e){

e.printStackTrace();

}

}

}

java.lang.NullPointerException

at com.mk.demo.jco.Connection.getFunction(Connection.java:69)

at com.mk.demo.jco.JcoTester.main(JcoTester.java:33)

Exception in thread "main" java.lang.RuntimeException: Problem retrieving JCO.Function object.

at com.mk.demo.jco.Connection.getFunction(Connection.java:72)

at com.mk.demo.jco.JcoTester.main(JcoTester.java:33)

Edited by: MonkD on Jun 9, 2009 3:20 PM

Edited by: MonkD on Jun 9, 2009 3:21 PM

Former Member
Not what you were looking for? View more on this topic or Ask a question