The advantage to this technique is obvious, as all SAP system parameters are now centralized and can be maintained within a single properties file. Likewise, the properties file allows you to use all of the available parameters listing in the JCo API.
To use this version of the createClient() method you first create a plain text file (called "sap.properties" in this example):
jco.client.client="100" jco.client.user="userid" jco.client.passwd="password" jco.client.lang="en" jco.client.sysnr="00" jco.client.ashost="mysaphost" jco.client.trace="1" jco.client.idle_timeout=1In addition to the normal system parameters, I have also specified that RFC trace be enabled and set the idle timeout for this JCo connection to one millisecond. Notice that because the timeout value must be passed to JCo as an integer, it cannot be specified using double quotes. The name attribute must be that which is specified in the JCo API, i.e. "jco.client.lang" is the only name attribute that allows you to specify a language value.
In order to use this properties file, call the createClient() method like this:
import com.sap.mw.jco.*; import java.io.*; import java.util.Properties; ... Properties
sapProperties = new Properties(); sapProperties.load(new FileInputStream("c:/dev/workspace/busptr/sap.properties")); JCO.Client connection = JCO.createClient(sapProperties); ... connection.disconnect();Note that in order to load the properties, you must specify its full filesystem path name. Alternatively, if the properties file exists in the same directory as the Java class being executed, no path name is required. However, this is not recommended due to the varying nature of how your application may be deployed.
In addition, your application can override the default parameters set in the properties file by call the setProperty() method:
sapProperties.setProperty("jco.client.user", "someotherguy");This is useful when you want to dynamically change settings, such as logging with the RFC trace option or using a login ticket instead of a user ID.
GETTING CONNECTED WITH JCO
Part 1: Specifying parameters as single String values
Part 2: Specifying parameters using a String array
Part 3: Specifying parameters using an external properties file
Part 4: Specifying parameters with a custom properties file
Review: Conclusion and more resources
This was first published in July 2005