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

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
Integrating Java apps and SAP with the JCo API -- resources

SAP Java and J2EE
SAP CTO Sikka: SAP's innovation gets overlooked
SAP CTO expects today's SAP applications to be running in 2020
Tips on SAP ABAP
How to provide an SAP R/3 4.5B application server with a Web service interface
Consuming a Web service from an SAP 4.6c R/3 application server
SAP NetWeaver Configuration and Customization
Is C, C++ and Java knowledge required when learning SAP?
How to be a self-taught NetWeaver and ABAP expert
Getting started with a NetWeaver career
An ABAP user wants to learn XI

SAP Web applications
SAP talent management FAQ: Fresh answers to frequently asked questions
How to do additional dialog processing after SAP COMMIT WORK statement
SAP TechEd Demo Jam 2009: Winners use beer keg in demo
SAP CTO expects today's SAP applications to be running in 2020
SAP TechEd 09 keynoters: Managing change today like trying to board a speeding train
How can I get an ABAP program displaying Excel data to wrap text?
An ABAP user wants to learn XI
SAP exec discusses Imagineering, the future of development
The stars of TechEd: SAP application demos
Validating table fields

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




SAP Exchange Infrastructure (XI) Research Papers
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, 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