Home > Part 3: Specifying parameters using an external properties file
Checklist:
EMAIL THIS LICENSING & REPRINTS

Part 3: Specifying parameters using an external properties file

15 Jul 2005

Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   

The third mechanism provided by the JCo API for specifying parameters to the createClient() method is that of passing an external properties file. This technique enables you to completely remove the system parameters from your code and allows you maintain those values in an external configuration file.

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=1
In 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

 Home: Introduction
 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


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


RELATED CONTENT
IT Checklists
Capacity planning checklist
How to build a business case for RFID
Part 1: Specifying parameters as single String values
Part 2: Specifying parameters using a String array
Part 4: Specifying parameters with a custom properties file
Conclusion and more resources

SAP Java / J2EE
Is this the quickest way to find a BADI?
Easily debug error messages in SAP processes
Is there a 'load of program' option in report generation?
Deleting entries from a dynamic table
Defining a structure in a report
Viewing a list of SAP interfaces
Which SAP implementation phase is Java necessary for?
Error when reading XML files in SAP
A parameter with no record available
Should an ABAP professional know Java?

SAP Web Applications
SAP exec discusses Imagineering, the future of development
Is there a 'load of program' option in report generation?
Deleting entries from a dynamic table
Defining a structure in a report
Validating table fields
The difference between field groups and internal tables
Unicode check error fix
How SEM relates to BI/BW
Methods for uploading SAP data
Error when reading XML files in SAP

RELATED GLOSSARY TERMS
Terms from Whatis.com − the technology online dictionary
Application Link Enabling  (SearchSAP.com)
R/2  (SearchSAP.com)

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary


HomeNewsTopicsBlogsTipsAsk the ExpertsWebcastsWhite PapersProducts
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Reprints  |  Site Map




All Rights Reserved, Copyright 2000 - 2008, TechTarget | Read our Privacy Policy
SearchSAP.com is a search service provided by TechTarget and is completely
independent of and not affiliated with SAP AG.
  TechTarget - The IT Media ROI Experts