You are on page 1of 27

SAP Java Connector

SAP AG

Presentation Content Overview

Overview
2

Architecture
3
4

SAP AG 2002, SAP JCo / 2

Scenarios

Design

Examples

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

Overview
2

Architecture
3
4

SAP AG 2002, SAP JCo / 4

Scenarios

Design

Examples

SAP Java Connector Architecture


Java

SAP Java
Connector

Java
Application

SAP System

Java
API

Function
Module

JNI Layer

libRFC

RFC
tRFC
qRFC

ALE
IDoc

RFC Layer

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


SAP JCos Java API
n Pluggable SAP JCo
Middleware Implementations
n RFC Middleware uses RFC
Library through Java Native
Interface (JNI) Layer

JAVA Application
SAP JCO Java API
Middleware Interface
RFC Middleware
JNI Layer
RFC Library
RFC
RFC
SAP System

SAP AG 2002, SAP JCo / 6

Presentation Content Overview

Overview
2

Architecture
3
4

SAP AG 2002, SAP JCo / 7

Scenarios

Design

Examples

SAP Java Connector Scenarios


Standalone Java Application as external RFC Client
n Numerous projects (marketplaces)

Java Server as external RFC Server


n SAP Business Connector
n Various projects (marketplaces)

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

Overview
2

Architecture
3
4

SAP AG 2002, SAP JCo / 9

Scenarios

Design

Examples

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 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 fields 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

byte[] type

int[] length

10

int[] offset

00

0A 0012 345D 0A7F DE02 48B3 74C1

01

BE 9876 543C 147C 583F CB03 93AA

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

PoolManager

Throughput

Connection

Pool

Client

MetaData

IMetaData

Record

ParameterList

Field

SAP AG 2002, SAP JCo / 17

Structure

Table

FieldIterator

BasicRepository

Server

FunctionInterface

IRepository

Repository

IFunctionInterface

Function

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.

Data stream

Segment type
E1MARAM
!
+-- E1MAKTM
!
+-- E1MAKTM
!
+-- E1MARCM
!
!
!
+-- E1MARDM
!
!
!
+-- E1MARDM
!
+-- E1MARCM
!
!
!
+-- E1MARDM
!
+-- E1MARMM
!
!
!
+-- E1MEANM
!
+-- E1MBEWM
!
+-- E1MLGNM
!
+-- E1MVKEM
!
+-- E1MLANM
!
+-- E1MTXHM
!
+-- E1MTXLM
!
+-- E1MTXLM

SAP AG 2002, SAP JCo / 19

005P-100

19941107BALLER

19990324D020033

005DPumpe GG IDESNORM 100-200

DE

005EPump GG IDESNORM

EN

100-200

0051000VDPALSQG

PD10110 0

M0.00 EXE

KCVDPALSQBG

0.000

FERTM001

0.000

0.000

0050001DL

0.000

0.000

0.000000

0050002DL

0.000

0.000

0.000000

0051300DBGVA

PD10110 0

0050001D
005PF 5

0.000
1

0051000
005100010 101

5.000
X

0.000

0.000

P-100

1292.7

0.000

000000000.000

7920S1292.7
0.000

0.000

PCE
0.000

100010

005* Vor Einbau, elektrischen Anschlu oder Inbetriebnahme bitte


005

0.000

ICX

005CA CTX11CTX21CTX31
005MVKE

0.000
0.000000

IC0.000

S1292.7

005001

0.000

0.000

20500000000009

005PF 0000120500000000009

M0.00 EXE800.000

Betriebsanleitungen unbedingt beachten.

1292.7
E1
0.000

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

Overview
2

Architecture
3
4

SAP AG 2002, SAP JCo / 21

Scenarios

Design

Examples

SAP Java Connector Example I/1


import com.sap.mw.jco.*;
public class Quicky {
static final String SID = B20";
IRepository repository;
public Quicky() {
try {
// Add a connection pool for
JCO.addClientPool(SID,
10,
000",
bbking",
lucille",
"EN",
pwdf024",
"06

// system ID used throughout the example


// the repository we gonna be using

the specified system


// alias for this pool
// max. number of connections
// SAP client
// userid
// password
// language
// host name
// 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";
IRepository repository;
static final int MAX_LISTENERS = 3;

// System ID
// Our repository
// 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.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other
software vendors.

Microsoft, WINDOWS, NT, EXCEL, Word, PowerPoint and SQL Server are registered trademarks of
Microsoft Corporation.

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.

ORACLE is a registered trademark of ORACLE Corporation.

UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.

Citrix, the Citrix logo, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, MultiWin and
other Citrix product names referenced herein are trademarks of Citrix Systems, Inc.

HTML, DHTML, XML, XHTML are trademarks or registered trademarks of W3C, World Wide Web Consortium,
Massachusetts Institute of Technology.

JAVA is a registered trademark of Sun Microsystems, Inc.

JAVASCRIPT is a registered trademark of Sun Microsystems, Inc., used under license for technology invented
and implemented by Netscape.

MarketSet and Enterprise Buyer are jointly owned trademarks of SAP AG and Commerce One.

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