Tips and Tricks: SAP JCo COnfiguration Accessing SAP Data Remotely with Java

February 2008

Situation
You need to get data from or push data to your ERP system, in this case SAP.

Problem

SAP has some interfaces defined for the movement of data to and from the system. However, often times these are bloated and require an in-depth knowledge of lengthy files known as IDOC’s. These files, while robust, are time consuming to construct outside of SAP.

Solution
Use Java and SAP Java Connector (SAP JCo) to communicate directly with SAP, through a Remote Function Call (RFC) or a remote enabled Business Application Programming Interface (BAPI).

Tips and Tricks
First, you’ll need to download the latest version of SAP JCo that can be used in your SAP environment. Then there are three pieces that have to be installed.
1)    Extract the JCo .zip file into a temp directory of your choice.
2)    Copy the file librfc32.dll and sapjcorfc.dll from your temp directory to your window’s system directory
3)    Add the sapjco.jar from your temp directory to the class path for all projects for which you want to use the SAP JCo.

You are now ready to create a class to connect to your SAP environment via Java Code. The connection to SAP is much like connecting to a database in that it can be configured in either a single connection per operation being done or it can be configured to have a pool from which a connection is acquired as needed and then released back into the pool. The pool approach is more efficient and is usually the preferred method of connection. To create a pool you need to create a pool manager which is natively global and add an initial client to the pool.

Once you have the pool created, you can call your RFC’s and BAPI’s by retrieving a function template (IFunctionTemplate) from the client retrieved from the pool. The function template is used to create a function (JCO.Function).  A function is an object and contains all the necessary information to execute the RFC.  In order to pass variables into the function, a parameter list needs to be created (JCO.ParameterList). The data returned from the RFC will also be contained in a parameter list; it will return information in one or more of the following data containers: JCO.Field, JCO.Structure, or JCO.Table. Don’t forget to release the client back to the pool after each RFC or BAPI that is used.

Using this approach, many processes can be executed inside of SAP from your external applications, this automating or making real-time processes that were formerly manual or batch driven. Reporting that was formerly only available from within SAP is now at the fingertips of users that would not normally have direct access to SAP.

If you need more information on how to interface your applications and communicate efficiently with your ERP system, contact Gary Codeluppi at 937-431-1026 x123 or visit the Ross Group Inc web site at www.rossgroupinc.com.
Comments (0)Add Comment
Write comment
 
 
smaller | bigger
 

busy
search | login