2
$\begingroup$

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!

$\endgroup$
1

1 Answer 1

2
$\begingroup$

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)

Prerequesits:

  • 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.user=USERNAME
jco.client.passwd=
jco.client.lang=de
jco.client.ashost=mySAP.myCompany.com
jco.client.client=090
jco.client.sysnr=03
jco.client.snc_mode=1
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
jco.destination.expiration_time=6000000000
jco.destination.expiration_check_period=6000000000

And now the Mathematica code for the connection:

Needs["JLink`"];

(* 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 *)
Environment`registerDestinationDataProvider[SAPDestinationDataProvider];
dest = JCoDestinationManager`getDestination[MakeJavaObject@"SAP"];

(* the ping will test the connection and bring up the SAP secure login client *)
dest@ping[];

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.

$\endgroup$

Your Answer

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

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