01 SAP Enterprise Connector

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

SAP Enterprise Connector

Siddhartha Bhattacharya
SAP Enterprise Connector Overview

Contents:
z SAP Enterprise Connector Architecture and Wizard
z Proxy Generation
z Programming Model

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector: Unit Objectives

After completing this unit, you will be able to:


z Understand the SAP Enterprise Connector
Architecture and Wizard
z Understand proxy generation
z Program using generated proxies

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector: Topic Objectives

After completing the next session, you will be able to:


z Understand the SAP Enterprise Connector
Architecture and Wizard

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector

The SAP Enterprise Connector is ..

„ A development tool that provides help classes and RFC function module
module
method calls for Java applications
„ Integrated into the Netweaver Developer Studio

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Remote call with and without proxies

„ These generated method calls and help classes are called Java Proxy.
Proxy.
„ The Java Proxy hides native SAP Java Connector (JCo
(JCo)) calls.
„ This architecture guarantees type-
type-secure data access and increases
client application stability.

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector Wizard

„ To Start the Enterprise Connector Wizard


„ Navigate to File -> New -> Other -> SAP Connectivity -> SAP
Enterprise Connector

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector Wizard

SAP Function Module

Clicking Finish generates


the proxy classes.

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector

„ You can get to this wizard by doing


„ File -> New -> Other -> SAP Connectivity -> SAP Enterprise Connector -> Enter package name and
folder
SAP Enterprise Connector: Topic Summary

You should now be able to:


z Understand the SAP Enterprise Connector
Architecture and Wizard

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector: Topic Objectives

After completing the next session, you will be able to:


z Understand proxy generation

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


RFC Interfaces and Java Proxy

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector

„ An RFC interface defines the name; the parameters (importing, exporting, changing, and table); and the
exceptions of an RFC function module
„ The individual parameters or data elements of a ABAP Dictionary data type are declared as attributes of
the generated Java classes
Java – ABAP Data type mapping

ABAP Elementary Data Types


„ The SAP Enterprise Connector maps the elementary ABAP data types to
primitive Java data types or existing Java classes

ABAP Type Java Type / Class


b short
C java.lang.String
D java.sql.Date
F double
g java.lang.String
I int
N java.lang.String
P java.math.BigDecimal
s short
T java.sql.Time
X byte[]
y byte[]

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Java – ABAP Data type mapping

ABAP Dictionary Data Types

„ The SAP Enterprise Connector maps the elementary ABAP/4 data typestypes
to primitive Java data types or existing Java classes
„ SAP Enterprise Connector generates an independent Java class for each
data type that is referenced by the selected RFC function module.
module.
„ Data elements of a ABAP Dictionary data type are defined as attributes
attributes of
the Java class. The getter and setter methods enable read and write
write
access to individual data elements.

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Java – ABAP Parameter mapping

Function module Parameters

„ SAP Enterprise Connector generates an input class that contains all the
importing and changing parameters of a function module.
„ In the same way, the tool generates an output class that combines
combines all the
exporting, changing, and table parameters.
„ The class names comprise function module names followed by the stringstring
_Input or _Output.
„ The individual parameters are defined as class attributes that the
the calling
program can access, to read or write, by using getter and setter
methods.

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Java – ABAP Table mapping

Function module Tables

„ The table parameters that a RFC function module returns are


represented as lists by the Java Proxy.
„ For each return table, the Java Connectivity Builder generates a Java
class. These lists are contained in the output class.
„ The line type of a table corresponds to a ABAP Dictionary data type.
type.
Therefore, the SAP Enterprise Connector generates a Java class forfor the
line type

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Java – ABAP Exception mapping

Function module Exceptions

„ A generated class, whose name consists of the function module name name
followed by the string _Fault, contains all the exceptions of the
the function
module.
„ Also generated is a Java exception class that a Java program can catch
and handle.
„ This exception class encapsulates the other class, and its name consists
of the function module name followed by the string _Fault_Exception
_Fault_Exception

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Java – ABAP Function module mapping

Function module

„ The generated Java proxy class contains all the selected function
function
modules, and these are defined as methods of this class.
„ The class name comprises a name that you enter during generation,
generation, and
the string _PortType
_PortType..

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Proxy Generation

The steps involved are...

1. Choose File → New → Other… → SAP Connectivity → SAP Enterprise Connector.


2. Choose Next. The SAP Enterprise Connector starts.
3. Enter the target folder or jar file for the source files that
that will be generated.
4. Enter the package name and the name of the class.
_PortType will be added to the name of the class automatically.
5. Choose Next.
6. Using either single server or load balancing, specify the server
server and logon
information.
7. Choose Next.
8. Select the function modules for which the proxies will be generated.
generated.

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector

y You can also display the selected function modules as a working set.
y You can use either Show Flat List (this is the default) to search
search for function modules, or Show
Component Hierarchy to browse for function modules.
y When searching for function modules, you can use asterisks ( * ) as wildcards. After entering the
search string, choose Search to display a list of function modules.
modules.
Project Structure

Generated Function Module

Generated Input Class

Generated Output Class

Generated Table Line Type


Generated Structure Class
Generated Table

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector: Topic Summary

You should now be able to:


z Understand proxy generation

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Using proxies to Call function module

The steps involved are...

„ Import the relevant packages for SAP Java Connector.


„ Connect to the SAP System.
„ Create an instance of the generated input class and set the input
input
parameters.
„ Create an instance of the generated proxy class.
„ Supply the proxy instance with the JCO.Client instance.
„ Create an instance of the generated output class and get the output
output
parameters.
„ Disconnect from the SAP System

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Using proxies to Call function module

Getting a SAP Connection


„ To establish a connection to the SAP System, instantiate a JCO.Client object
using the JCO.createClient()
JCO.createClient() method.

// Step 1. Create a JCO.Client connection

JCO.Client client = JCO.createClient(“client", “username",


“password", “language", “server",“sysnr");

// Step 2. Connect to the SAP System

client.connect();

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector

„ Replace client, username, password, language, server and sysnr with actual SAP R/3 login values.
Using proxies to Call function module

Getting a SAP Connection using a Connection Pool


„ An alternate way of getting a connection is using a Connection Pool.
Pool. The
advantages of having a Connection Pool are
„ Connections can be shared between multiple clients.
„ Avoid expensive connect() and disconnect() calls.

// Step 1. Create a Connection Pool

JCO.Pool pool = JCO.getClientPoolManager().getPool(POOL_NAME);

if (pool == null) {

OrderedProperties logonProperties =

OrderedProperties.load("/logon.properties");

JCO.addClientPool(POOL_NAME, // pool name

5, // maximum number of connections

logonProperties); // properties

// Step 2. Getting a Connection

JCO.getClient(POOL_NAME);

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector

„ Replace client, username, password, language, server and sysnr with actual SAP R/3 login values.
Using proxies to Call function module

Prepare the Input Class


„ Create an instance of the input class. If there are any inputs required
required for the
function call set them in this step.

// Step 3. Prepare the Input Class.

Bapi_Companycode_Getlist_Input input = new


Bapi_Companycode_Getlist_Input();

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Using proxies to Call function module

Instantiate the proxy class


„ Create an instance of the proxy class. This class contains methods
methods to invoke
the BAPI. Pass the connection object created in Step 1 to this class.
class.

/*

* Step 4. Setup the proxy class to invoke the BAPI.

* Pass the client object created to the proxy class

*/

BAPI_COMPANY_CODE_PortType proxy = new


BAPI_COMPANY_CODE_PortType();

proxy.messageSpecifier.setJcoClient(client);

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Using proxies to Call function module

Invoke the BAPI


„ Invoke the BAPI by calling the appropriate method on the proxy class.
class. Pass
the input class as a parameter to the called method.

// Step 5. Receive the results of the BAPI Execution in the


Output class

Bapi_Companycode_Getlist_Output output =
proxy.bapi_Companycode_Getlist(input)

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Using proxies to Call function module

Disconnect from SAP


„ After the output is received disconnect from the SAP System.

// Step 6. Disconnect from the SAP System

client.disconnect();

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Using proxies to Call function module

Display Results
„ Iterate over the List returned and display the results.

// Step 7. Display the results

Bapi0002_1Type_List list=
output.get_as_listCompanycode_List();

System.out.println ( "Company Code, Company Name ");

for ( int i = 0 ; i < list.size(); i++ )

Bapi0002_1Type type = list.getBapi0002_1Type(i);

System.out.println ( type.getComp_Code() +", "+


type.getComp_Name());

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


Using proxies to Call function module

Console output
„ The result will be displayed on the console

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector: Topic Summary

You should now be able to:


z Program using generated proxies

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector


SAP Enterprise Connector : Unit Summary

You should now be able to:


z Understand the SAP Enterprise Connector
Architecture and wizard
z Understand proxy generation
z Program using generated proxies

© SAP AG 2004 / Siddhartha Bhattacharya / SAP Enterprise Connector

You might also like