I am trying to get some references for accessing an SAP/ERP server from Mathematica. It has been suggested that possibly JLink or NetLink could be used. Assuming that I have the server address, username and password required for access, what code from either of the above links would be required to get into an SAP server? Thanks for any advice!

  • 1
    $\begingroup$ How do you access it normally outside of Mathematica? Does it have a SOAP/REST API, or something else? It could be JSON, but their documentation is confusing jargon and uses screenshots developers.sap.com/tutorials/hcp-abh-getting-started.html $\endgroup$
    – flinty
    Commented Jul 7, 2020 at 13:21

1 Answer 1


Each SAP R/3 system is configured differently but I will show a scenario with:

  • Mathematica & J/Link
  • SAP JCo a.k.a the SAP connector for Java
  • Property file
  • SAP secure login client for a SNC connection (you may not need this)


  • Download the SAP JCo version 3.1 from the SAP website
  • depending on your connection method you may use a simple user/password or a more sophisticated secure method, e.g. using SNC (secure network connection) with a certificate -- please check the required system data with your admin
  • install "SAP secure login client" if you will connect via SNC
  • create a working directory (in this case under Windows D:/sapclient)
  • put the sapjco3.jar and the sapjco3.dll in the working directory
  • in working directory create a property file named SAP.jcoDestination

Lets have a look in the property file

jco.client.snc_myname=p:CN=Little John, O=myCompany, S=Little, G=John, SN=USERNAME
jco.client.snc_partnername=p:CN=mySAP.myCompany.com, C=US, O=myCompany, OU=myORG

And now the Mathematica code for the connection:


(* Use SAP JCo framework 3.1, prerequisites: #1 sapjco3.dll in classpath #2 Installed SAP Secure login client *)
AddToClassPath["D:/sapclient", "D:/sapclient/sapjco3.jar"];
LoadJavaClass /@ {"com.sap.conn.jco.ext.Environment", "com.sap.conn.jco.JCoDestinationManager"}

(* load properties that hold essential params for connecting to a SAP R/3 system *)
connectionProperties = JavaNew["java.util.Properties"];
connectionProperties@load@JavaNew["java.io.FileInputStream", "D:/SAPClient/SAP.jcoDestination"];

(* implement the two essential methods of the DestinationDataProvider interface *)
SAPDestinationDataProvider = ImplementJavaInterface["com.sap.conn.jco.ext.DestinationDataProvider", {"getDestinationProperties" -> "getDestinationPropertiesImpl", "supportsEvents" -> "supportsEventsImpl"}];
getDestinationPropertiesImpl["SAP"] := connectionProperties;
supportsEventsImpl[] := MakeJavaObject[False];

(* registering the provider and getting a JCoDestination dest *)
dest = JCoDestinationManager`getDestination[MakeJavaObject@"SAP"];

(* the ping will test the connection and bring up the SAP secure login client *)

You might output the destination with:

(dest@getAttributes[]@toString[]) // StringReplace[#, "\r\n" -> "\n"] &

Needless to say, this is only the connection. In order to do something: JCoFunction, JCoRecord are your friend to execute SAP functions.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.