Skip to Content

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

Establishing a connection via Class


i have to classes. The first is for establishing a connection and the second for execute bapi.

Looks so:


public class SapConnection {

private static JCoDestination ABAP_AS;

static class MyDestinationDataProvider implements DestinationDataProvider


private DestinationDataEventListener eL;

private Properties ABAP_AS_properties;

public Properties getDestinationProperties(String destinationName)


if(destinationName.equals("ABAP_AS") && ABAP_AS_properties!=null)

return ABAP_AS_properties;

return null;

//alternatively throw runtime exception

//throw new RuntimeException("Destination " + destinationName + " is not available");


public void setDestinationDataEventListener(DestinationDataEventListener eventListener)


this.eL = eventListener;


public boolean supportsEvents()


return true;


void changePropertiesForABAP_AS(Properties properties)




ABAP_AS_properties = null;





if(ABAP_AS_properties==null || !ABAP_AS_properties.equals(properties))


ABAP_AS_properties = properties;






public JCoDestination con() throws JCoException{

Properties connectProperties = new Properties();

connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "xxx");

connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "x");

connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "xx");

connectProperties.setProperty(DestinationDataProvider.JCO_USER, "xxx");

connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "xxx");

connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "xx");

MyDestinationDataProvider myProvider = new MyDestinationDataProvider();;


ABAP_AS = JCoDestinationManager.getDestination("ABAP_AS");

return ABAP_AS;



Edited by: igorechek on Jun 9, 2011 10:27 PM

Former Member
Former Member replied

In your class "bapi_reqgetitem" you have at least two calls to con:


JCoFunction function = sapConnection.con().getRepository().getFunction("BAPI_REQUISITION_GETITEMS");



It fails upon the second call since you try to register a destination data provider for the second time. There are several ways around that. The quick and dirty solution is to exchange the line in your first class;


if (! {;

A better solution would be of course to take the JCoDestination that you get as a returned instance from sapConnection.con() and work with that. It would look something like that:

JCoDestination jcoDestination = sapConnection.con()
JCoFunction function = jcoDestination.getRepository().getFunction("BAPI_REQUISITION_GETITEMS");

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question