Java SAP Integration
Java SAP Integration
November 2004
Abstract
Enterprises of all descriptions have long sought to integrate and manage all their information
assets within a single system. The goal remains elusive because enterprises create and store
their assets in a myriad of disparate systems - relational databases, mainframes, different
operating systems, hierarchical repositories, and so on. Using new and existing assets in an
efficient, integrated, and interchangeable manner has become the key to surviving, and
thriving in the new economy.
SAP remains the world leader in enterprise-software domain, with over 11000 installations
worldwide. With over 60% of market share in ERP segment, it becomes an obvious choice for
the EAI and EII product vendors to target SAP R/3 Enterprise as a data source, and therein
emerges the need for integration. With the emergence of Java as a platform for developing
enterprise applications and its portability across different Operating Systems, it becomes the
obvious platform for integration with SAP R/3 Enterprise.
Contact details
Copyright © 2004 Persistent Systems. All rights reserved. No part of this publication may be reproduced,
transmitted, transcribed, stored in a retrieval system, or translated into any language, in any form or by any
means, electronic, mechanical, photocopying, recording, or otherwise, without prior written permission
from Persistent Systems. Written and printed in India.
The information furnished herein is believed to be accurate and reliable. However, no responsibility is
assumed by Persistent Systems for its use, or for any infringements of patents or other rights of third parties
resulting from its use.
TABLE OF CONTENTS
Introduction 5
Aim 5
Intended Audience 5
Issues 12
Performance 12
Connection Pooling 12
Use a Fresh Function Object 12
Use Only One Repository 13
Inactive Table Parameters 13
Appending Multiple Table Rows 13
Synchronization 13
Appendix 14
Terms 14
Sample Code 14
Reference 17
Introduction
Aim
This section provides you 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 white paper assumes that you already know
Java. Some knowledge of SAP is also desirable, but you should be able to get
by even if you don’t know much about SAP. This document will cover all
aspects of integration with SAP R/3 Enterprise using Java as a platform.
Intended Audience
This document is intended for developer(s)/architect(s) embarking on EAI/EII
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.
Architecture
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.
The R/3 Basis is the software that implements SAP three-tier client/server
architecture. It consists of application modules and application servers, which
are distinct components. The application modules support all of a company’s
business transactions and are integrated interactively. All application modules
share data through the R/3 database, which contains the data for all modules.
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 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.
The java application uses only JCo’s java apis for connecting with SAP R/3
Enterprise. RFC middleware uses RFC Library through JNI layer for
connecting to the SAP R/3.
Creating Repository
A Repository object is created by calling method createRepository(). A
Repository object contains meta-data for all function modules at runtime.
[st2]
Creating Function
A function object is created by calling method getFunction(). [st4]
Getting Connection
A connection object is retrieved from connection pool by calling method
getClient(). [st5]
Providing Inputs
Inputs are passed to the function module by calling method
getImportParameterList(). [st6]
Executing Function
A function module is executed by calling method execute(). [st7]
Accessing Output
Output of the function module is accessed by calling method
getExportParameterList(). [st8]
Issues
Performance
Connection Pooling
Connection pools are critical for the performance of SAP R/3 as well as for
application integration due to the following:
• Overhead of logging on to SAP system is avoided because the
connection stays open and can be reused.
• Maximum number of connections concurrently used, are restricted
thus preventing the use of too many SAP resources.
Synchronization
In order to optimize performance, JCo itself synchronizes access to JCO.Pool
and JCO.Repository objects. Everything else is not synchronized. In a multi-
threaded environment, care should be taken while sharing objects (like
JCO.Table objects) between different threads. Sharing connections
(JCO.Client objects) is disallowed and will lead to an exception.
Appendix
Terms
Business Framework Architecture (BFA): Business Framework
Architecture is a component-based architecture enabling software
components from SAP and other software vendors to communicate and be
integrated with each other.
Advanced Business Application Programming (ABAP): All application
programs in SAP business applications are created in Advanced Business
Application Programming (ABAP), SAP’s own, interpretive language.
Function Module (FM): Function Modules are the ABAP programs deployed
in the SAP R/3 system for implementing additional program logic.
Function Builder: Function Builder is a SAP tool that can be used to
generate, test, and administer function modules in a SAP R/3 system.
CPI-C: Common Programming Interface Communication a platform-
independent API that interfaces to a common set of APPC (Advanced
Program-to-Program Communication) verbs.
JNI: Java Native Interface is the native programming interface for Java that
is part of the JDK.
EAI: Enterprise Application Integration is unrestricted sharing of data and
business processes throughout the networked applications or data sources in
an organization.
EII: Enterprise Information Integration provides seamless integration of
disparate data sources on an enterprise scale, provides strategic advantage
organizations require.
RPC: Remote Procedure Call is calling a procedure that need not exist in the
same address space as the calling procedure.
LUW: Logical Unit of Work is a set of transactions where either all are
successfully applied against the database, or none have any impact on the
database.
Sample Code
Shown below is the code snippet to understand how java can be used for
invoking function module in SAP R/3 Enterprise. The code snippet explains
inbound (Java calls ABAP); by invoking BAPI BAPI_SALESORDER_GETLIST for
fetching a list of sales order from SAP R/3 Enterprise.
import com.sap.mw.jco.*;
public class SalesOrder {
static final String SID = "R3";
// The repository we will be using
IRepository repository;
public SalesOrder() {
try {
}
catch (JCO.Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
}
input.setValue("0000001200", "CUSTOMER_NUMBER" );
input.setValue( "1000", "SALES_ORGANIZATION");
input.setValue( "0", "TRANSACTION_GROUP" );
// Print results
if (sales_orders.getNumRows() > 0) {
// Loop over all rows
do {
System.out.println("-----------------------");
// Loop over all columns in the current row
for (JCO.FieldIterator
e=sales_orders.fields();
e.hasMoreElements(); ) {
JCO.Field field = e.nextField();
System.out.println(field.getName()
+ ":\t" + field.getString());
}//for
} while(sales_orders.nextRow());
}else {
System.out.println("No results found");
}//if
} else {
System.out.println("Function not found in R/3 system.");
}//if
}
catch (Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}
finally {
// Release the client to the pool
JCO.releaseClient(client);
}
}
protected void cleanUp() {
}
public static void main(String[] argv){
SalesOrder order = new SalesOrder();
order.salesOrders();
order.cleanUp();
}
}
Reference
Books
[1] Enterprise Java for SAP (Indian Edition) by Austin Sincock
Internet
[2] Tutorial (JCo Tutorial.pdf) shipped with JCo software
[3] Help available at SAP Help Portal http://help.sap.com
[4] Help available at http://ifr.sap/com
[5] Help available at http://sapgenie.com/