|
New Page 1
|

SAP Netweaver
- Java Connector -
Page 5 of 6
6.0 Using the SAP Java Connector
SAP’s new Java middleware, the SAP Java Connector
(JCO) allows customers and partners to easily build SAP-enabled
components in Java. JCO supports both inbound (Java calls ABAP) and
outbound (ABAP calls Java) calls in desktop and server applications.
In this Sample Program we connect to SAP and
call two BAPIs.
Import statements: Any program using JCO should
contain the following import statement:
import com.sap.mw.jco.*;
Otherwise, you have to fully qualify each class and interface which
is very inconvenient.
Connecting to SAP
JCO.Client mConnection;
A connection (or session) with SAP is handled by
class JCO.Client
try {
mConnection =
JCO.createClient("400", // SAP client
"c3026902", // userid
"********", // password
"EN", // language
"iwdf5020", // host name
"00"); // system number
mConnection.connect();
}
catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
"A Client object is created via a call to
createClient(). You can use a specific application server (as in the
above code) or a server group (load balancing)." REFER the JCO
Javadoc for the overloaded createClient() method for the latter
possibility.
"The Client class's connect () method tries to
log on to SAP. If that fails for any reason, an exception is thrown.
If the call succeeds, we can now stay connected for as long as we
like. When we are done, we can call disconnect () to explicitly log
off."


|
New Page 1
|