You are on page 1of 27

SAP Java Connector

SAP AG
Presentation – Content Overview

1 Overview

2 Architecture

3 l Scenarios

4 l Design

5 Examples

ã SAP AG 2002, SAP JCo / 2


SAP Java Connector – Overview

n Enables communication between any SAP System and Java


(supports communication with SAP R/2 and SAP R/3 3.1 and
later)
n Supports inbound (Java calls ABAP) as well as outbound
(ABAP calls Java) communication
n Support for Unicode and Non-Unicode Systems
n Hides all difficult parts like codepages, data type conversions,
connection pooling, etc. from the programmer
n Hides RFC details from programmers
n Hides DDIC details from programmers
n Consistent and easy-to-learn class design and API
n Highly optimized source code leads to unprecedented
performance

ã SAP AG 2002, SAP JCo / 3


Presentation – Content Overview

1 Overview

2 Architecture

3 l Scenarios

4 l Design

5 Examples

ã SAP AG 2002, SAP JCo / 4


SAP Java Connector – Architecture

Java
SAP Java
Connector

Java Java mySAP Technology


Application API

Function ALE
JNI Layer Module IDoc

RFC
libRFC RFC Layer
tRFC
qRFC
Java API comprises
n Dynamic metadata lookup and caching
n JCO.Function object offers ready-to-use containers for parameters and/or
tables
n Service APIs useful to build higher level applications on top
ã SAP AG 2002, SAP JCo / 5
SAP Java Connector – Architecture

n Java Applications only use JAVA Application


SAP JCo‘s Java API
SAP JCO Java API
n Pluggable SAP JCo
Middleware Implementations Middleware Interface

RFC Middleware
n RFC Middleware uses RFC
Library through Java Native JNI Layer
Interface (JNI) Layer
RFC Library

RFC

RFC

SAP System

ã SAP AG 2002, SAP JCo / 6


Presentation – Content Overview

1 Overview

2 Architecture

3 l Scenarios

4 l Design

5 Examples

ã SAP AG 2002, SAP JCo / 7


SAP Java Connector – Scenarios

Standalone Java Application as external RFC Client


n Numerous projects at SAPMarkets

Java Server as external RFC Server


n SAP Business Connector
n Various at SAPMarkets

Middleware based on SAP JCo


n JRA for J2EE Application Server
n RFCAdapter
n ObjectFactory
n ObjectBuilder

Interface between SAP J2EE and SAP Web AS

ã SAP AG 2002, SAP JCo / 8


Presentation – Content Overview

1 Overview

2 Architecture

3 l Scenarios

4 l Design

5 Examples

ã SAP AG 2002, SAP JCo / 9


SAP Java Connector – Design

Small and fast


n Minimizes number of internally used objects

n Does not use Java codepage converters

n Avoids using multidimensional arrays

n Minimizes calls between Java and JNI layer

n Manipulates Java member variables directly instead of using


function calls in JNI layer

ã SAP AG 2002, SAP JCo / 10


SAP Java Connector – Design

Consistent and easy-to-learn API


Facts about function parameters
n SAP Web AS Functions have Import-, Export-, and Table
Parameters
n Parameters can be atomic (Integer, Float, String, etc.)
n Parameter can also be composite (heterogeneous Structures,
Tables)
Common representation of parameters
n A parameter list can be considered to be a heterogeneous
structure

n A heterogeneous structure in turn can be seen as a table with


just a single row

ã SAP AG 2002, SAP JCo / 11


SAP Java Connector – Design

Consistent and easy-to-learn API


A JCO.Function object
n Represents a SAP Function Module in Java
n Contains meta-data about the call interface and all data types, i.e.
(Import-, Export-, Table Parameters, Name, etc.)
n Contains ready-to-use data containers for parameters and / or tables

Function objects are build from templates


n Templates contain all meta-data that completely specify a function
n But they do not have any preinitialized containers yet

Function templates and therefore JCO.Functions can be obtained


dynamically from a repository for a given SAP system
n Client side caching ensures efficiency
n There is one repository for each dedicated SAP R/3 System

ã SAP AG 2002, SAP JCo / 12


SAP Java Connector – Design

Consistent and easy-to-learn API


n Simple Repository API
IRepository repository = JCO.createRepository(…);
JCO.Function function =
repository.getFunctionTemplate(“WebAS_FUNCTION”).
getFunction();

n Consistent API for access to atomic parameters, structures,


tables
JCO.ParameterList import =
function.getImportParameterList();
String s = import.getString(“PARAM1”);
int i = import.getInt(“PARAM1”);
JCO.Structure struct = import.getStructure(“PARAM3”);
JCO.Table table = import.getTable(“PARAM4”);

ã SAP AG 2002, SAP JCo / 13


SAP Java Connector – Design

Performance
How to avoid extensive object creation?
n Why not using a heterogeneous buffer (e.g. one dimensional
array) divided into cells, each cell holding the field‘s value?
n Since strings are by far the most occurring field types, a
character array would be the natural choice for a buffer.

What are the advantages/disadvantages?


n Minimal number of objects
n Fast access to string fields
n Fast access from middleware (e.g. JNI Layer)
n Non-string fields would need some nasty binary
encoding / decoding mechanism

ã SAP AG 2002, SAP JCo / 14


SAP Java Connector – Design

Performance

C I P X byte[] type

6 2 2 4 int[] length

0 6 8 10 int[] offset

S T R I N G 00 0A 0012 345D 0A7F DE02 48B3 74C1

R O W 2 01 BE 9876 543C 147C 583F CB03 93AA

R O W 3 61 AC 0001 234C 1567 F59A FCEF AC13

buffer[offset[column] + row * row_length]

ã SAP AG 2002, SAP JCo / 15


SAP Java Connector – Design

Performance
n Metadata for functions and parameters will be fetched at first
request and stored in the repository cash

n Connection pooling
Avoids expensive connect(), disconnect() calls

n Performance measuring: number of calls, sent and received


bytes, time measuring for middleware calls, marshalling and
unmarshalling, total request time

ã SAP AG 2002, SAP JCo / 16


SAP Java Connector – Design

Attributes Throughput Connection BasicRepository IRepository

PoolManager Pool Client Server Repository

MetaData IMetaData FunctionInterface IFunctionInterface Function

Record

ParameterList Structure Table

Field FieldIterator

ã SAP AG 2002, SAP JCo / 17


SAP Java IDoc Class Library – Overview

Goal: Offer business level access to binary data

The technical level of an IDoc


Defined by the three record types compatible with the IDoc Interface
n Control record (containing the routing and processing information)
n Data record (containing the business data)
n Status record (containing status information)

The business level of an IDoc


Defined by the segments of an IDoc Interface. Segments are hierarchically
ordered structures used to interpret the data stream of the data record.
An IDoc Type is defined by the revelant
n Segments
n Attributes of these segments
(e.g. minimum and maximum usage, hierarchical sequence)

ã SAP AG 2002, SAP JCo / 18


Java IDoc Class Lib. – Semant. Access to IDoc-Data

Schematic example: IDoc: MATMAS01 (Material Master)


Material No.
Segment type Data stream

E1MARAM 005P-100 19941107BALLER 19990324D020033 KCVDPALSQBG FERTM001


!
+-- E1MAKTM 005DPumpe GG IDESNORM 100-200 DE
!
+-- E1MAKTM 005EPump GG IDESNORM 100-200 EN
!
+-- E1MARCM 0051000VDPALSQG PD10110 0 M0.00 EXE 0.000 0.000 0.000
! !
! +-- E1MARDM 0050001DL 0.000 0.000 0.000000
! !
! +-- E1MARDM 0050002DL 0.000 0.000 0.000000
!
+-- E1MARCM 0051300DBGVA PD10110 0 M0.00 EXE800.000 0.000 0.000
! !
! +-- E1MARDM 0050001D 0.000 0.000 0.000000
!
+-- E1MARMM 005PF 5 1 20500000000009 IC0.000 0.000 0.000 0.000
! !
! +-- E1MEANM 005PF 0000120500000000009 ICX
!
+-- E1MBEWM 0051000 S1292.7 1292.7 1 7920S1292.7 1292.7 1
!
+-- E1MLGNM 005001 5.000 0.000 0.000 PCE E1
!
+-- E1MVKEM 005100010 101 X 000000000.000 0.000 0.000 0.000
!
+-- E1MLANM 005CA CTX11CTX21CTX31
!
+-- E1MTXHM 005MVKE P-100 100010
!
+-- E1MTXLM 005* Vor Einbau, elektrischen Anschluß oder Inbetriebnahme bitte
!
+-- E1MTXLM 005 Betriebsanleitungen unbedingt beachten.

ã SAP AG 2002, SAP JCo / 19


SAP Java IDoc Class Library – Features

Provides structured, high-level access to IDocs in Java


n Easy navigation through IDoc segment trees (generic)
n Easy access to single data fields (generic)
n Access to all available IDoc meta data

Supports effective and robust programming


n Typesafe creation and modification of IDocs, segments and
fields
n Optional syntax checking (3 different checks)
n Creation of IDoc-HTML files for easy debugging

Supports effective and robust programming


n Supports IDoc base types and customer extension types
n Interface based architecture allows own extensions and
implementations

ã SAP AG 2002, SAP JCo / 20


Presentation – Content Overview

1 Overview

2 Architecture

3 l Scenarios

4 l Design

5 Examples

ã SAP AG 2002, SAP JCo / 21


SAP Java Connector – Example I/1

import com.sap.mw.jco.*;

public class Quicky {


static final String SID = “B20"; // system ID used throughout the example
IRepository repository; // the repository we gonna be using

public Quicky() {
try {
// Add a connection pool for the specified system
JCO.addClientPool(SID, // alias for this pool
10, // max. number of connections
“000", // SAP client
”bbking", // userid
”lucille", // password
"EN", // language
“pwdf024", // host name
"06” // system number
);
// Create a new repository
repository = JCO.createRepository("MYRepository", SID);
} catch (JCO.Exception ex) {
System.out.println("Caught an exception: \n" + ex);
}//try
}

ã SAP AG 2002, SAP JCo / 22


SAP Java Connector – Example I/2

// Retrieves and prints list of sales orders


public void salesOrders() {
JCO.Client client = null;

try {
// Get a function template from the repository
JCO.Function function = repository.getFunctionTemplate(
"BAPI_SALESORDER_GETLIST").getFunction();

// Fill in input parameters


JCO.ParameterList input = function.getImportParameterList();
input.setValue("0000001200", "CUSTOMER_NUMBER" );
input.setValue("1000", "SALES_ORGANIZATION");
input.setValue("0", "TRANSACTION_GROUP" );
// Get a client from the pool
client = JCO.getClient(SID);
// Execute function the remote system
client.execute(function);
// Print return message
JCO.Structure ret=function.getExportParameterList().getStructure("RETURN");
System.out.println("RETURN MESSAGE: " + ret.getString("MESSAGE"));
// Get a reference to the table which contains the orders
JCO.Table orders=function.getTableParameterList().getTable("SALES_ORDERS");

ã SAP AG 2002, SAP JCo / 23


SAP Java Connector – Example I/3
// Print results
if (orders.getNumRows() > 0) {
// Loop over all rows
do {
// Loop over all columns in the current row
for (JCO.FieldIterator e = orders.fields(); e.hasMoreElements();) {
JCO.Field field = e.nextField();
System.out.println(field.getName() + ":\t" + field.getString());
}//for
} while(orders.nextRow());
} else {
System.out.println("No results found");
}//if
} catch (Exception ex) {
System.out.println("Caught an exception: " + ex);
} finally {
// Always release client !!!
JCO.releaseClient(client);
}//try
}
// Main program
public static void main(String[] argv) {
Quicky quicky = new Quicky();
quicky.salesOrders();
}
}
ã SAP AG 2002, SAP JCo / 24
SAP Java Connector – Example II/1

import com.sap.mw.jco.*;

public class QuickyServer {


static public class Listener extends JCO.Server {
// Constructor takes gateway host, service, program ID, and repository
public Listener(String gwhost, String gwserv, String program_id, IRepository repos)
{
super(gwhost, gwserv, program_id, repos);
}
// Handles incoming requests
protected void handleRequest(JCO.Function function)
{
if (function.getName().equals("BAPI_COMPANYCODE_GETLIST")) {
JCO.Table codes = function.getTableParameterList().getTable(
"COMPANYCODE_LIST");
codes.deleteAllRows();
codes.appendRow();
codes.setValue("XXXX", "COMP_CODE");
codes.setValue("This is field comp_name","COMP_NAME");
} else {
throw new JCO.AbapException("FUNCTION_NOT_SUPPORTED",
"The requested service is not supported");
}//if
}
}//Listener

ã SAP AG 2002, SAP JCo / 25


SAP Java Connector – Example II/2
String POOL = "T20"; // System ID
IRepository repository; // Our repository
static final int MAX_LISTENERS = 3; // Max. listener
Listener listeners[] = new Listener[MAX_LISTENERS]; // Listeners

public QuickyServer() {
JCO.addClientPool(POOL,MAX_LISTENER,"400","tarzan","jane","EN",
"iwdf5020.wdf.sap-ag.de","T20","SPACE");
repository = JCO.createRepository("QUICKY", POOL);
}
public void startThemAll() {
for (int i = 0; i < MAX_LISTENERS; i++) {
listeners[i] = new Listener("iwdf5020", "sapgw00", ”QUICKY", repository);
try {
listener[i].start();
} catch (Exception ex) {
System.out.println("Could not start listener !\n" + ex);
}//try
}//for
}
public static void main(String[] argv) {
QuickyServer qserver = new QuickyServer();
qserver.startThemAll();
}

ã SAP AG 2002, SAP JCo / 26


Copyright 2002 SAP AG. All Rights Reserved

n No part of this publication may be reproduced or transmitted in any form or for any purpose without the express
permission of SAP AG. The information contained herein may be changed without prior notice.
n Some software products marketed by SAP AG and its distributors contain proprietary software components of other
software vendors.
n Microsoft®, WINDOWS®, NT®, EXCEL®, Word®, PowerPoint® and SQL Server® are registered trademarks of
Microsoft Corporation.
n IBM®, DB2®, DB2 Universal Database, OS/2®, Parallel Sysplex®, MVS/ESA, AIX®, S/390®, AS/400®, OS/390®,
OS/400®, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere®, Netfinity®, Tivoli®,
Informix and Informix® Dynamic ServerTM are trademarks of IBM Corporation in USA and/or other countries.
n ORACLE® is a registered trademark of ORACLE Corporation.
n UNIX®, X/Open®, OSF/1®, and Motif® are registered trademarks of the Open Group.
n Citrix®, the Citrix logo, ICA®, Program Neighborhood®, MetaFrame®, WinFrame®, VideoFrame®, MultiWin® and
other Citrix product names referenced herein are trademarks of Citrix Systems, Inc.
n HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C®, World Wide Web Consortium,
Massachusetts Institute of Technology.
n JAVA® is a registered trademark of Sun Microsystems, Inc.
n JAVASCRIPT® is a registered trademark of Sun Microsystems, Inc., used under license for technology invented
and implemented by Netscape.
n MarketSet and Enterprise Buyer are jointly owned trademarks of SAP AG and Commerce One.
n SAP, SAP Logo, R/2, R/3, mySAP, mySAP.com and other SAP products and services mentioned herein as well as
their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other
countries all over the world. All other product and service names mentioned are trademarks of their respective
companies.

ã SAP AG 2002, SAP JCo / 27

You might also like