SAP Java Connectorread.pudn.com/downloads145/ebook/633576/Java调用SAP... · 2009-01-19 · (ABAP...

27
SAP AG SAP Java Connector

Transcript of SAP Java Connectorread.pudn.com/downloads145/ebook/633576/Java调用SAP... · 2009-01-19 · (ABAP...

SAP AG

SAP Java Connector

� SAP AG 2002, SAP JCo / 2

Presentation – Content Overview

Architecture

�Design

�Scenarios

Examples

1

3

2

Overview

4

5

3

2

4

5

� SAP AG 2002, SAP JCo / 3

SAP Java Connector – Overview

� Enables communication between any SAP System and Java(supports communication with SAP R/2 and SAP R/3 3.1 andlater)

� Supports inbound (Java calls ABAP) as well as outbound(ABAP calls Java) communication

� Support for Unicode and Non-Unicode Systems

� Hides all difficult parts like codepages, data type conversions,connection pooling, etc. from the programmer

� Hides RFC details from programmers

� Hides DDIC details from programmers

� Consistent and easy-to-learn class design and API

� Highly optimized source code leads to unprecedentedperformance

� SAP AG 2002, SAP JCo / 4

Presentation – Content Overview

Architecture

�Design

�Scenarios

Examples

3

2

Overview

4

5

3

2

4

5

1

� SAP AG 2002, SAP JCo / 5

SAP Java Connector – Architecture

Java

JavaAPI

SAP JavaConnector

SAP System

RFC RFC LayerlibRFC

JNI LayerFunctionModule

JavaApplication

tRFCqRFC

ALEIDoc

Java API comprises� Dynamic metadata lookup and caching� JCO.Function object offers ready-to-use containers for parameters and/or

tables� Service APIs useful to build higher level applications on top

� SAP AG 2002, SAP JCo / 6

SAP Java Connector – Architecture

SAP JCO Java API

Middleware Interface

RFC Middleware

JNI Layer

RFC Library

RFC

RFC

SAP System

JAVA Application� Java Applications only useSAP JCo‘s Java API

� Pluggable SAP JCoMiddleware Implementations

� RFC Middleware uses RFCLibrary through Java NativeInterface (JNI) Layer

� SAP AG 2002, SAP JCo / 7

Presentation – Content Overview

Architecture

�Design

�Scenarios

Examples

3

2

Overview

4

5

3

2

4

5

1

� SAP AG 2002, SAP JCo / 8

SAP Java Connector – Scenarios

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

Java Server as external RFC Server� SAP Business Connector� Various projects (marketplaces)

Middleware based on SAP JCo� JRA for J2EE Application Server� RFCAdapter� ObjectFactory� ObjectBuilder

Interface between SAP J2EE and SAP Web AS

� SAP AG 2002, SAP JCo / 9

Presentation – Content Overview

Architecture

�Design

�Scenarios

Examples

3

2

Overview

4

5

3

2

4

5

1

� SAP AG 2002, SAP JCo / 10

SAP Java Connector – Design

Small and fast� Minimizes number of internally used objects

� Does not use Java codepage converters

� Avoids using multidimensional arrays

� Minimizes calls between Java and JNI layer

� Manipulates Java member variables directly instead of usingfunction calls in JNI layer

� SAP AG 2002, SAP JCo / 11

SAP Java Connector – Design

Consistent and easy-to-learn APIFacts about function parameters� SAP Web AS Functions have Import-, Export-, and Table

Parameters

� Parameters can be atomic (Integer, Float, String, etc.)

� Parameter can also be composite (heterogeneous Structures,Tables)

Common representation of parameters� A parameter list can be considered to be a heterogeneous

structure

� A heterogeneous structure in turn can be seen as a table withjust a single row

� SAP AG 2002, SAP JCo / 12

SAP Java Connector – Design

Consistent and easy-to-learn APIA JCO.Function object � Represents a SAP Function Module in Java� Contains meta-data about the call interface and all data types, i.e.

(Import-, Export-, Table Parameters, Name, etc.)� Contains ready-to-use data containers for parameters and / or tables

Function objects are build from templates� Templates contain all meta-data that completely specify a function� But they do not have any preinitialized containers yet

Function templates and therefore JCO.Functions can be obtaineddynamically from a repository for a given SAP system� Client side caching ensures efficiency� There is one repository for each dedicated SAP System

� SAP AG 2002, SAP JCo / 13

SAP Java Connector – Design

Consistent and easy-to-learn API� Simple Repository APIIRepository repository = JCO.createRepository(…);

JCO.Function function =repository.getFunctionTemplate(“WebAS_FUNCTION”).getFunction();

� 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 / 14

SAP Java Connector – Design

PerformanceHow to avoid extensive object creation?� Why not using a heterogeneous buffer (e.g. one dimensional

array) divided into cells, each cell holding the field‘s value?

� Since strings are by far the most occurring field types, acharacter array would be the natural choice for a buffer.

What are the advantages/disadvantages?� Minimal number of objects

� Fast access to string fields

� Fast access from middleware (e.g. JNI Layer)

� Non-string fields would need some nasty binaryencoding / decoding mechanism

� SAP AG 2002, SAP JCo / 15

SAP Java Connector – Design

Performance

S T R I N G 00 0A 0012345D0A7FDE0248B374C1

C I P X

0 6 8 10

6 2 2 4

byte[] type

int[] length

int[] offset

R O W 2 01 BE 9876543C147C583FCB0393AA

R O W 3 61 AC 0001234C1567F59AFCEFAC13

buffer[offset[column] + row * row_length]

� SAP AG 2002, SAP JCo / 16

SAP Java Connector – Design

Performance� Metadata for functions and parameters will be fetched at first

request and stored in the repository cash

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

� Performance measuring: number of calls, sent and receivedbytes, time measuring for middleware calls, marshalling andunmarshalling, total request time

� SAP AG 2002, SAP JCo / 17

SAP Java Connector – Design

Client Server

ConnectionThroughputAttributes

PoolManager Pool

IRepositoryBasicRepository

Repository

MetaData

ParameterList

Record

Structure Table

IMetaData

Field FieldIterator

FunctionFunctionInterface IFunctionInterface

� SAP AG 2002, SAP JCo / 18

SAP Java IDoc Class Library – Overview

Goal: Offer business level access to binary data

The technical level of an IDocDefined by the three record types compatible with the IDoc Interface

� Control record (containing the routing and processing information)� Data record (containing the business data)� Status record (containing status information)

The business level of an IDocDefined by the segments of an IDoc Interface. Segments are hierarchicallyordered structures used to interpret the data stream of the data record.An IDoc Type is defined by the revelant

� Segments� Attributes of these segments

(e.g. minimum and maximum usage, hierarchical sequence)

� SAP AG 2002, SAP JCo / 19

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

Material No.

�Schematic example: IDoc: MATMAS01 (Material Master)

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 / 20

SAP Java IDoc Class Library – Features

Provides structured, high-level access to IDocs in Java� Easy navigation through IDoc segment trees (generic)� Easy access to single data fields (generic)� Access to all available IDoc meta data

Supports effective and robust programming� Typesafe creation and modification of IDocs, segments and

fields� Optional syntax checking (3 different checks)� Creation of IDoc-HTML files for easy debugging

Supports effective and robust programming� Supports IDoc base types and customer extension types� Interface based architecture allows own extensions and

implementations

� SAP AG 2002, SAP JCo / 21

Presentation – Content Overview

Architecture

�Design

�Scenarios

Examples

3

2

Overview

4

5

3

2

4

5

1

� SAP AG 2002, SAP JCo / 22

SAP Java Connector – Example I/1

import com.sap.mw.jco.*;

public class Quicky {static final String SID = “B20"; // system ID used throughout the exampleIRepository repository; // the repository we gonna be using

public Quicky() { try {

// Add a connection pool for the specified systemJCO.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 repositoryrepository = JCO.createRepository("MYRepository", SID);

} catch (JCO.Exception ex) {System.out.println("Caught an exception: \n" + ex);

}//try}

� SAP AG 2002, SAP JCo / 23

SAP Java Connector – Example I/2

// Retrieves and prints list of sales orderspublic void salesOrders() {

JCO.Client client = null;

try { // Get a function template from the repositoryJCO.Function function = repository.getFunctionTemplate(

"BAPI_SALESORDER_GETLIST").getFunction();

// Fill in input parametersJCO.ParameterList input = function.getImportParameterList(); input.setValue("0000001200", "CUSTOMER_NUMBER" ); input.setValue("1000", "SALES_ORGANIZATION"); input.setValue("0", "TRANSACTION_GROUP" );

// Get a client from the poolclient = JCO.getClient(SID);

// Execute function the remote system client.execute(function);

// Print return messageJCO.Structure ret=function.getExportParameterList().getStructure("RETURN");System.out.println("RETURN MESSAGE: " + ret.getString("MESSAGE"));

// Get a reference to the table which contains the ordersJCO.Table orders=function.getTableParameterList().getTable("SALES_ORDERS");

� SAP AG 2002, SAP JCo / 24

SAP Java Connector – Example I/3// Print resultsif (orders.getNumRows() > 0) {

// Loop over all rowsdo { // Loop over all columns in the current rowfor (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 programpublic static void main(String[] argv) {Quicky quicky = new Quicky();quicky.salesOrders();

} }

� SAP AG 2002, SAP JCo / 25

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 requestsprotected 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 / 26

SAP Java Connector – Example II/2

String POOL = "T20"; // System IDIRepository repository; // Our repositorystatic 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 / 27

Copyright 2002 SAP AG. All Rights Reserved

� 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.