JCO is a high-performance, JNI-based middleware that implements the RFC (Remote Function Call) protocol of SAP.
1 , JCo the installation
Download Jco from Http://files.cnblogs.com/byfhd/jco.rar and copy Librfc32.dll and Sapjcorfc.dll to Winnt "SYSTEM32" after decompression, Add Sapjco.jar to the project's classpath.
2 , with SAP the connection
The JCO supports two modes of connection, direct connections and connection pools.
Direct connections:
Import com.sap.mw.jco.*;
Public TutorialConnect1 () {
JCO. Client mconnection;
try {
Mconnection = Jco.createclient ("001",//SAP Client
"",//UserID
"* * * *",//password
NULL,//language
"",//server host name
"XX"); // System number mconnection.connect ();
Mconnection.disconnect ();
} catch (Exception ex) {
}
}
Connection pools:
Static final String pool_name = "POOL";
Public TutorialConnect2 () {
JCO. Client mconnection;
try {
JCO. Pool pool = Jco.getclientpoolmanager (). Getpool (Pool_name);
if (pool = = null) {
Orderedproperties properties = orderedproperties.load ("/logon.properties");
Jco.addclientpool (Pool_name,//POOL NAME
5,//maximum number of connections
Logonproperties); Properties
}
Mconnection = Jco.getclient (pool_name);
} catch (Exception ex) {
} finally { Returns a connection to the connection pool, or causes no connection to be available
Jco.releaseclient (mconnection);
}
}
Definition of logon.properties file:
jco.client.client=001
Jco.client.user=userid
jco.client.passwd=****
Jco.client.ashost=hostname
jco.client.sysnr=00
3 , the SAP to operate
There are jco.repository objects in SAP that contain the run environment metadata for the RFM of SAP.
JCO. Repository mrepository;
Mrepository = new JCO. Repository ("Arasoft", mconnection);
The constructor contains two parameters, the first one is an arbitrary name, and the second is the connection pool or Jco.client object.
The Ifunctiontemplate object contains a specific RFM meta-data, JCO. The function represents an RFM that contains all the parameters. The relationship between them is similar to the relationship between class and object in Java.
Ifunctiontemplate ft = mrepository.getfunctiontemplate ("Bapi_salesorder_getlist");
FT NULL indicates no corresponding RFM found in SAP
if (ft = = null) return null;
JCO. function function = Ft.getfunction ();
JCO. The Parameterlist object contains input, output, and table parameters that do the function.
Client = Jco.getclient (SID); Get the client from the pool
JCO. Parameterlist input = Function.getimportparameterlist ();
Set the parameter, the parameter name is the second parameter, the parameter value is the first parameter,
Input.setvalue ("0000001200", "Customer_number");
Input.setvalue ("n", "sales_organization");
Client.execute (function);
Download Jco:http://files.cnblogs.com/byfhd/jco.rar
SAP Java Connector (JCo)