14
SAP Java Connector (JCO) Swati Bhayana

SAP Java Connector

Embed Size (px)

Citation preview

Page 1: SAP Java Connector

SAP Java Connector (JCO)

Swati Bhayana

INTRODUCTION

Page 2: SAP Java Connector

Aim

SAP Java Connector (SAP JCo) is a middleware component that enables the development of SAP-compatible components and applications in Java. SAP JCo supports communication with the SAP Server in both directions: inbound calls (Java calls ABAP) and outbound calls (ABAP calls Java).This white paper provides an overview of the SAP R/3 Enterprise, different integration interfaces exposed by it and integration of an application with SAP R/3 using Java platform. This paper assumes that you already know Java. Knowledge of SAP is not desirable, but after reading this you should be able to get some basics of SAP as well.

Intended Audience

This document is intended for developer(s)/architect(s) embarking on projects involving integration with SAP R/3. They will find this document suitable for obtaining a quick overview of the SAP R/3 Enterprise and different integration interfaces exposed by the same. It will also give them a quick overview of the SAP’s Java Connector, with some details on the issues involved in such integration projects.

SAP R/3 ENTERPRISE

Overview

SAP’s R/3 System has set new norms for standard software that can be universally implemented. R/3 uses advanced development techniques to achieve comprehensive integration of business administration and data processing. It combines state-of-the-art technology with comprehensive business administration functionality to provide a fully integrated business solution for an enterprise.

SAP stands for Systems Applications and Products for data processing.

Architecture

SAP R/3 is SAP's integrated software solution for client/server and distributed open systems. SAP's R/3 is the world's most-used standard business software for client/server computing. R/3 meets the needs of a customer from the small grocer with 3 users to the multi-billion dollar companies The software is highly customizable using SAP's proprietary programming language, ABAP/4. R/3 is scalable and highly suited for many types and sizes of organizations.

The R/3 architecture is comprised of application and database servers. The application servers house the software and the databases servers handle document updates and master file databases. The system can support an unlimited number of servers and a variety of hardware configurations. SAP R/3 is based on various hardware and software architectures, running on most types of UNIX, on Windows NT and OS/400.

SAP R/3 is event-driven transaction processing software for business events in an organization’s primary value chain. Transaction processing systems supported by enterprise software are most concerned with the day-to-day needs of a business in conducting its on-going activities. R/3 Modules

Page 3: SAP Java Connector

R/3's applications are modules.  They can be used either alone or combined with other solutions.  The integration capability of these applications increases the benefits derived for any company.

Logistics - Logistics comprises all processes involved in purchasing, materials management, manufacturing, warehousing, quality management, plant maintenance, service management and sales and distribution.  All applications access a shared consistent database, supported by production data management.

SD: Sales & Distribution   SD actively supports sales and distribution activities with outstanding functions for pricing, prompt order processing, and on-time delivery, interactive variant configuration, and a direct interface to profitability analysis and production.

PP: Production Planning and Control        PP provides comprehensive process for all types of manufacturing: from repetitive, make-to-order, and assemble-to-order production, through process, lot and make-to-stock manufacturing, to integrated supply chain management with functions extended MRP.

PS: Project System        PS coordinates and controls all phases of a project, in direct cooperation with Purchasing and Controlling, from quotation to design and approval, to resource management and cost settlement.

MM: Materials Management        MM optimizes all purchasing processes with workflow-driven processing functions, enables automated supplier evaluation, lowers procurement adn warehousing costs with accurate inventory and warehouse management, and integrates invoice verification.

QM: Quality Management        QM monitors, captures, and manages all processes relevant to quality assurance along the entire supply chain, coordinates inspection

Sales &Sales &DistributionDistribution

SDSD

MMMM

PPPP

QMQMPMPM

HRHR

COCO

AMAM

PSPS

WFWF

ISIS

MaterialsMaterialsManagementManagement

ProductionProductionPlanningPlanning

QualityQualityManagementManagement

Plant Plant MaintenanceMaintenance

Human ResourcesHuman Resources

Financial Financial AccountingAccounting

ControllingControlling

AssetAssetManagementManagement

WorkflowWorkflow

Industry SolutionsIndustry Solutions

SAPSAPR/3R/3 Project Project

SystemsSystems

FIFI

Page 4: SAP Java Connector

processing, initiates corrective measures, and integrates laboratory information systems.

PM: Plant Maintenance        PM provides planning, control, and processing of scheduled maintenance, inspection, damage-related maintenance, and service management to ensure availability of operational systems, including plants and equipment delivered to customers.

SM: Service Management        SM provides highly integrated customer service functionality to compete in today's global markets.

PDM: Product Data Management        PDM supports in creating and managing product data throughout the product life cycle.

Financials - Financials is a suite of integrated financial application components encompasses all aspects of financial accounting, investment management, controlling, treasury management, and enterprise controlling.

FI: Financial Accounting        FI collects all the data in company relevant to accounting, providing complete documentation and comprehensive information, and is at the same an up-to-the-minute basis for enterprise-wide control and planning.

CO: Controlling        CO is a complete array of compatible planning and control instruments for company-wide controlling systems, with a uniform reporting system for coordinating the contents and procedures of company's internal processes.

IM: Investment Management        IM offers integrated management and processing of investment measures and projects from planning to settlement, including pre-investment analysis and depreciation simulation.

TR: Treasury        TR is a complete solution for efficient financial management that ensures the liquidity of worldwide company, its structures, financial assets, profitability and minimizes risks.

EC: Enterprise Controlling        EC continuously monitors company's success factors and performance indicators on the basis of specially prepared management information.

Human Resources - HR provides solutions planning and managing company's human resources, using integrated applications that cover all personnel management tasks and help simplify and speed the process.

PM: Personnel Management        PM is a complete solution for personnel administration, recruitment management, travel management, benefits administration and salary administration.

OM: Organizational Management        OM assists in maintaining an accurate picture of organization's structure, no matter how fast it changes.  It is systematic and forward planning tool that considers the final effects of all personnel events thus it's complete solution for personnel cost planning.

PA: Payroll Accounting        PA addresses payroll functions from a global point-of-view and gives the capability to centralize payroll processing or decentralize the data based on country or legal entities.

TM: Time Management        TM is integrated with payroll accounting, controlling, production planning, plant maintenance, project system, external services and shift planning.  It provides with a variety of standard reports that will assist in tracking and analyzing employee time with completeness and accuracy.

PD: Personnel Development        PD assists with planning, monitoring, and analyzing scheduled seminars, training courses, and business events, registration and booking, price determination and invoicing.

Page 5: SAP Java Connector

SAP Integration Interfaces

Remote Function Calls (RFC)

A Remote Function Call (RFC) is the call of function module in a partner system. The caller is the RFC client and the called partner is the RFC server. RFC is based on the known RPC model from the UNIX-TCP/IP environment. RFC in SAP environment is based on a CPI-C interface implemented by SAP.

The remote call of a function module is easier for an application programmer to use than program-to-program communication, because data is exchanged only using predefined parameters.

SAP BO, BOR and BAPI

SAP Business Objects (BO)

Business model objects for the real world (for example, employees, customer orders, and so on) are reproduced in R/3 as business objects. A business object encapsulates the business processes and the data linked to it. These objects can be seen as being multi-layered.

Page 6: SAP Java Connector

The innermost layer is made up of the actual data and its structures. The second layer maintains integrity. It represents the business logic of the object and describes the business rules and limitations for the business object. The interface layer describes the implementation and structure of the object. The interface layer allows access to the attributes, methods, and events that are defined for the object.

SAP Business Object Repository (BOR)

The Business Object Repository (BOR) contains the SAP business object types and SAP interface types as well as their components, such as methods, attributes, and events. The BOR has the following functions:

• Enables an object-oriented view of the R/3 System data and processes.

• Arranges the various interfaces in accordance with the component hierarchy.

• Manages BAPIs in release updates.

SAP Business Application Programming Interface (BAPI)

SAP BAPIs provide developers with stable, reliable interfaces for accessing the functionality offered by SAP business objects. BAPIs can reduce the development cost by providing built-in functionality through predefined methods of the SAP business objects. These methods can reduce programming time in deployment projects.

Page 7: SAP Java Connector

Application Link Enabling (ALE) and IDocs

Application Link Enabling (ALE) is an important middleware tool in SAP’s Business Framework Architecture. ALE is the exchange of messages controlled from a business point of view. It can integrate business processes between R/3 systems and non-R/3 systems as well as between R/3 systems. Application systems are loosely coupled in an ALE integrated system. Data is exchanged asynchronously, whereby the data arrives in the receiver system, even if the receiver system cannot be connected to at the time the data is sent. ALE uses synchronous communication for receiving data only.

Page 8: SAP Java Connector

An Intermediate Document (IDoc) is a container for exchanging data between R/3, R/2 and non-SAP systems. Non SAP-systems can use IDocs as the standard interface for data transfer. The IDoc interface consists of the definition of a data structure and the processing logic for this data structure.

SAP JAVA CONNECTOR (JCO)

SAP Java Connector (SAP JCo) is a middleware component that enables the development of SAP-compatible components and applications in Java. SAP JCo supports communication with the SAP Server in both directions: inbound calls (Java calls ABAP) and outbound calls (ABAP calls Java).

SAP’s java middleware, the SAP Java Connector (JCo) allows SAP customers and partners to easily build SAP-enabled components and applications in Java. It enables communication between SAP System and Java (supports communication with SAP R/2, R/3 3.1 and later).

SAP JCo offers the following functions for creating SAP-compliant Java applications:

SAP JCo has RFC middleware based on the JNI (Java Native Interface).

It supports SAP (R/3) systems from Release 3.1H upwards, and other mySAP components that have BAPIs or RFMs (Remote Function Modules).

You can execute function calls inbound (Java client calls BAPI or RFM) and outbound (ABAP calls Java Server).

With SAP JCo, you can use synchronous, transactional, and queued RFC.

Connection pooling (important for Web servers)

SAP JCo can be used on different platforms

Extensive code page handling, including multi-byte languages.

SAP JCo Architecture (Standalone Version)

The following diagram shows the technical schema of data conversion in the SAP JCo (standalone version). Starting from a Java application, a Java method is forwarded via the JCo Java API (Application Programming Interface) and an additional Middleware Interface to RFC Middleware, where it is converted to an RFC (ABAP) call using the JNI(Java Native Interface) layer, and sent to the SAP system. Using the same method in the other direction, an RFC Call is converted to Java and forwarded to the Java application.

Page 9: SAP Java Connector

Downloading JCo

You need to be an SAP customer or partner (with a valid SAPnet (OSS) userid) to download JCo. Go to http://service.sap.com/connectors and follow the download instructions. You will also find the complete list of supported platforms here.

Installing JCo

JCo 2.0 is available with SAP Basis Release 6.20. JCo 2.0 does not support JDK 1.1 anymore, but requires Java 2 (JDK 1.2 and later). If you still need to use JDK 1.1, please keep using JCo 1.1 (1.1.03 or later).

The following instructions apply to Windows 32 platforms. The instructions for installing JCo on other platforms are contained in the appropriate JCo download.

1. Create a directory, e.g., c:\JCo, and unzip the JCo zip file to that directory, keeping the directory structure intact.2. Copy the librfc32.dll file from your JCo root directory to C:\WINNT\SYSTEM32 unless the version you already have there is newer than the one supplied with JCo.3. Make sure that sapjco.jar (found in your JCo root directory) is in the class path of any project that wants to use JCo. For production deployment, the following files from the JCo zip file are required:

· sapjco.jar · librfc32.dll · sapjcorfc.dll

Along with this you also get following in downloaded zip file –

The docs directory contains the Javadocs for JCo. Start with the index.html file.

Page 10: SAP Java Connector

The demo directory contains some sample programs, including, but not limited to,the samples discussed in this text.

CONNECTING TO SAP

JCo supports two programming models for connecting to SAP: direct connections, which you create and hold on to as long as you want, and connection pools, from which you take a connection when you need it and to which you return it as soon as possible so that others can use it. These two models can be combined in one application. If you are building web server applications, you definitely want to use connection pools, but they can also be used in desktop applications.

Direct Connection

Below are the attributes that needs to be defined in the program to connect to SAP in case of Direct Connection.

1. Introduce New classes -JCO9 - The main class of the SAP Java Connector.JCO - Attributes Attributes of a connection, e.g., the release of the SAP system.

2. Import statements -Any program using JCo should contain the following import statement: import com.sap.mw.jco.*; Otherwise, you have to fully qualify each JCo class and interface which is very inconvenient.

3.Defining a connection variable - JCO.Client mConnection; A connection with SAP is handled by an object of class JCO.Client. Since the term client means a logical partition of an SAP system (and has to be entered when you log on to SAP, for example), this text calls an object of class JCO.Client a connection.

4. Creating a JCO.Client object-

// Change the logon information to your own system/usermConnection = JCO.createClient("001", // SAP client"<userid>", // userid"****", // password"EN", // language (null for the default language)"<hostname>", // application server host name"00"); // system number

Use the createClient() method of class JCO to create JCO.client object. There are several overloaded versions of this method to support:· Connections to a specific application server · Connections to a load balancing server group,· Connections based on the information in a java.util.Properties object.

5. Opening the connection - Creating the JCO.Client object does not connect to SAP, but a subsequent call to connect() will accomplish this:

try {mConnection.connect();}catch (Exception ex) {ex.printStackTrace();System.exit(1);

Page 11: SAP Java Connector

}

6. Calling a function -Now we are ready to call functions in SAP. For testing the connection just print out the RFC attributes for our connection.System.out.println(mConnection.getAttributes());

.7. Closing the connection -After we have accomplished whatever it was we wanted to do (call one BAPI or a few hundred), eventually we want to disconnect again:

mConnection.disconnect();

As opposed to using connection pools , where you want to return the connection to the pool as soon as possible, for direct connections it is not a good idea toconnect to SAP, call one function, and disconnect again for every function call. There is some overhead involved in logging on to SAP and therefore we should stay connected until we are finished or until we know that there will be no further activity for quite some time.

Connection PoolsIn (web) server applications, at least to some extent generic userids are used to log on to SAP. In that case it makes sense to use connection pooling. A JCo connection pool is identified by its name and is global within the Java Virtual Machine (JVM). All connections in a pool use the same system/userid/client information.There can be as many pools as you need, though.Below are the attributes that needs to be defined in the program to connect to SAP in case of connection Pools –

1. New classes introduced -JCO.Pool - Represents one connection pool.JCO.PoolManager - Manages all connection pools within one JVM.

2. Selecting a pool name -static final String POOL_NAME = "Pool";

As far as JCo is concerned, you can use any pool name. Just remember that a pool isglobal within the JVM, so different applications running in the same JVM need to followsome naming standard to avoid unpleasant surprises.

3. Does the pool exist already? –

JCO.Pool pool = JCO.getClientPoolManager().getPool(POOL_NAME);if (pool == null) {

All pools are managed by the global JCo PoolManager object (a singleton), which can be access via the getClientPoolManager() method of class JCO. The getPool() methodtries to access a pool with the specific pool name. null is returned if no such pool exists.

4. Creating a connection pool –

OrderedProperties logonProperties =OrderedProperties.load("/logon.properties");JCO.addClientPool(POOL_NAME, // pool name5, // maximum number of connectionslogonProperties); // properties

To create a new connection pool, use method addClientPool(). The maximum number of connections specified can never be increased, so choose a number large enough for application. Several overloaded versions of addClientPool() allows to specify logon information

Page 12: SAP Java Connector

in different ways. In the code above, we have chosen to use a Properties object. Any other way of creating a Properties object could have been used instead.

The following is a sample logon.properties file:

jco.client.client=001jco.client.user=useridjco.client.passwd=****jco.client.ashost=hostnamejco.client.sysnr=00

Whenever we need an actual connection from the pool, we will borrow (acquire) it, makeone or more calls to SAP, and finally return (release) the connection to the pool.

If all connections in the pool are in use and the pool has reached its maximum size, JCo will wait for a certain time. If no connection has become available in the meantime, JCo will throw an exception.

As long as our application is stateless – as far as SAP is concerned – we will always release the connection back to the pool as soon as we have finished with the SAP calls connected to one activity. Not necessarily after each SAP call, though. In other words, if you need to call multiple RFMs in a sequence, uninterrupted by user or other external interaction, you should keep the connection, and return it after all your calls are done.

Note that when you use a connection pool, you never call the connect() or disconnect()methods of JCO.Client. The PoolManager takes care of all this as appropriate.

RELATED CONTENT

http://service.sap.com www.sdn.sap.com www.sap-img.com www.erpgenie.com