Show TOC Start of Content Area

Background documentation Using the SAP System Connector  Locate the document in its SAP Library structure

The SAP System adapter for the SAPEnterprise Portal 6.0 is a connector framework implementation based on the J2EE Java Connectivity Architecture (JCA 1.0), the SAP RFC library, and the SAP Java Connector (JCO). It enables connectivity to SAP ERP systems, CRM (Customer Relations Management) and BI (Business Intelligence).

The connector framework has connection management. This overcomes a common problem that occurs when using the JCo client service, where the developer hat to take care about connection management himself. Therefore it is strongly recommended not to use JCo client service any more and migrate existing EP 5.0 applications that use the JCo client service to Connector Framework.

The Connector Framework BAPI Example in the PDK

See also

Prerequisites for using a connector

 

Connector Gateway Service

Example for a connection to a SAP system using the connector gateway service:

IConnection connection = null;
try {  // get the Connector Gateway Service
    
Object connectorservice = PortalRuntime.getRuntimeResources().getService( IConnectorService.KEY);
    IConnectorGatewayService cgService =(IConnectorGatewayService) connectorservice;
    
if (cgService == null) {
       response.write(
"Error in get Connector Gateway Service <br>");
    }
    
try {
        connection = cgService.getConnection(sapsystem, request);
    } 
catch (Exception e) {
        response.write(
"Connection to SAP system failed <br>");
    }
    
if (connection == null) {
        response.write(
"No connection <br>");
    }
    
else {
        response.write(
"Connection succesful");
    }
catch (Exception e) {
    response.write(
"Exception occurred");
}

 

Executing a BAPI Function

In the following example we execute a BAPI function. The result is a returned RecordSet object. A RecordSet object has a pointer that points to its current data row. Initially, the pointer is positioned before the first row. The method next moves the pointer to the next row. If there are no more rows, the method next returns false.

try {
    
// Get the Interaction interface for executing the command
    
IInteraction ix = connection.createInteractionEx();
    
// Get interaction spec and set the name of the command to run
    
IInteractionSpec ixspec = ix.getInteractionSpec();
    
// the well known example BAPI SALESORDER
    
String functionName = "BAPI_SALESORDER_GETLIST";
    
// Put Function Name into interaction Properties.
    
ixspec.setPropertyValue("Name", functionName);
    
// return structure
    
String function_out = "SALES_ORDERS";
    RecordFactory rf = ix.getRecordFactory();
    MappedRecord input = rf.createMappedRecord(
"input");
    
// put function input parameters
    
input.put("CUSTOMER_NUMBER"new String("0000001172"));
    input.put(
"SALES_ORGANIZATION"new String("1000"));
    MappedRecord output = (MappedRecord) ix.execute(ixspec, input);
    Object rs = 
null;
    
try {
        Object result = output.get(function_out);
        
if (result == null) {
            rs = 
new String(" ");
        } 
else if (result instanceof IRecordSet) {
            rs = (IRecordSet) result;
        }
        
// result object returned
        
else {
            rs = result.toString();
        }
    } 
catch (Exception ex) {
        printException(ex);
    }
    
return rs;
catch (Exception e) {
        printException(e);
}

 

Connecting to an SAP System on WebAS 6.20 without the Connector Service

You can connect to a SAP system directly by providing the username and the password, for example for testing purposes. The EISConnection can be initialized directly with JNDI support.

// physical connection
IConnection mm_con = null;
//connection factory of the SAP connector to get the connection
IConnectionFactory connectionFactory;
Context initctx = 
null;

try {
    
//get the initial JNDI context
    
Hashtable env = null;
    initctx = 
      
new com.sapportals.portal.prt.jndisupport.InitialContext(env);
    
// perform JNDI lookup to get the connection factory
    
connectionFactory = 
     (IConnectionFactory) initctx.lookup(
"EISConnections/SAPFactory");
catch (Exception e) {
}

try {
    
// retrieve the ConnectionSpec and set the values
    
IConnectionSpec spec = connectionFactory.getConnectionSpec();

/*
 * set connection properties according to 
SAP JCO javadoc:
 * static String[][] login_params  = {
             *{ "client" ,   "000"                    },
             *{ "user"   ,   "timtaylor"              },
             *{ "passwd" ,   "binford"                },
             *{ "language",  "EN"                     },
             *{ "ashost",    "mymachine.mycompany.com"};
             *...
 *};
*/
// set properties
    
spec.setPropertyValue("client""000");
    spec.setPropertyValue(
"user""timtaylor");
    spec.setPropertyValue(
"passwd""binford");
    spec.setPropertyValue(
"lang""EN");
    spec.setPropertyValue(
"ashost""myserver.mycompa??/Ad??Yd??Rny.corp");
    spec.setPropertyValue(
"sysnr""00");

    
// Retrieve the connection handle
    
mm_con = connectionFactory.getConnectionEx(spec);
    mm_con.close();

catch (Exception e) {
}

 

Connecting to an SAP System on WebAS 6.40 without the Connector Service

The connector JDNI name was changed from WebAS 6.20 to 6.40. In 6.20, as shown in the above sample, look for "EISConnections/<connector_name>" to get a connector factory instance.

When migrating code with such a hard-coded look-up string to WebAS 6.40, the JNDI lookup name for the connector needs to be changed to the following format:

deployedAdapters/<connector_name>/shareable/<connector_name>

For example:

    ...

    ...

    ...

try {
    
//get the initial JNDI context
    
Hashtable env = null;
    initctx = 
      
new com.sapportals.portal.prt.jndisupport.InitialContext(env);
    
// perform JNDI lookup to get the connection factory
    
connectionFactory = 
     (IConnectionFactory) initctx.lookup(
"deployedAdapters/SAPFactory/
     shareable/SAPFactory for SAP connector");

    deployedAdapters/SAPFactory/shareable/SAPFactory for SAP connector

    ...

    ...

    ...

 

Recommendation

It is highly recommended that content developers use the portal connector gateway service, as described above, to establish a connection to the back end. Code that uses this service doesn't require any change when migrating to WebAS 6.40.

See also:

Using the JDBC Connector

 

 

End of Content Area