Hi,
i have to classes. The first is for establishing a connection and the second for execute bapi.
Looks so:
first
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)
{
if(properties==null)
{
ABAP_AS_properties = null;
eL.deleted("ABAP_AS");
}
else
{
if(ABAP_AS_properties==null || !ABAP_AS_properties.equals(properties))
{
ABAP_AS_properties = properties;
eL.updated("ABAP_AS");
}
}
}
}
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();
com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProvider);
myProvider.changePropertiesForABAP_AS(connectProperties);
ABAP_AS = JCoDestinationManager.getDestination("ABAP_AS");
return ABAP_AS;
}
}
Edited by: igorechek on Jun 9, 2011 10:27 PM