For this, you need a Java library called "SAP JCo" (=Java Connector), the current version number is 3 and you can download it from the SAP Service Marketplace (you need a customer ID though). There are two directions you can connect SAP and Java:
1.) You can call ABAP FMs from Java Programm.
* Go to SAP transaction se37 and make sure your FM (in my example "Z_YOUR_FM" is marked as "remote".
* Use some Java-Code like this:
Properties properties = new Properties();
properties.setProperty(Des
properties.setProperty(Des
properties.setProperty(Des
properties.setProperty(Des
properties.setProperty(Des
properties.setProperty(Des
File file = new File("sapconnection.jcoDes
FileOutputStream stream = new FileOutputStream(file, false);
properties.store(stream, "SAP connection properties");
stream.close();
JCoDestination destination = JCoDestinationManager.getD
System.out.println(destina
JCoRepository repository = destination.getRepository(
JCoFunction processTisTask = repository.getFunction("Z_
JCoParameterList importParameter = processTisTask.getImportPa
JCoStructure data = importParameter.getStructu
data.setValue("FIELD1", 1);
data.setValue("FIELD2", "two");
importParameter.setValue("
processTisTask.execute(des
2.) You can run a Java Programm as a Server that can be accessed from SAP.
* First create a connection (aka "destination") via SAP transaction "sm59"
* Create an ABAP FM in se37 and mark it as remotely callable.
* Use Java code similar to this:
JCoServer server = JCoServerFactory.getServer
JCoServerFunctionHandler handler = new YourHandler();
DefaultServerHandlerFactor
new DefaultServerHandlerFactor
factory.registerHandler("Z
server.setCallHandlerFacto
server.start();
public class YourHandler implements JCoServerFunctionHandler {
@Override
public void handleRequest(JCoServerCon
throws AbapException {
String test = function.getImportParamete
// ...
}
}
* Run your Java server program.
* In SAP check via sm59 that your program is found.
* When you now call your FM from ABAP code like this:
CALL FUNCTION 'Z_YOUR_FM' DESTINATION dest EXPORTING ...
where "dest" is the destination that you created in sm59. Your Java-Handler gets called.
Main Topics
Browse All Topics





by: a_bPosted on 2009-10-13 at 20:55:47ID: 25567118
I have not used SAP before, but can you interact directly with the SAP database? Or do you have some api that you call for interacting with SAP?