The SAP System connector for the SAP NetWeaver Portal is a connector framework implementation based on the J2EE Java Connectivity Architecture (JCA 1.0), the SAP RFC library. It enables connectivity to SAP ERP systems, CRM (Customer Relations Management) and BI (Business Intelligence).
For more information, see Using Existing Connectors.
The following example illustrates connecting to a SAP system using the connector gateway service:
Example
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"); }
The following example shows executing a BAPI function that returns a RecordSet object.
Example
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); }
The following is relevant for the older versions of WebAS (AS Java).
The JNDI name of the connector was changed in WebAS 6.40. In 6.20, you use the lookup string EISConnections/<connector_name> to get a connector factory instance.
When migrating code with such a hard-coded lookup string to WebAS 6.40, change the JNDI lookup name for the connector to the following format:
deployedAdapters/<connector_name>/shareable/<connector_name>.
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");
Recommendation
It is highly recommended to use the portal connector gateway service, as described above, to establish a connection to the back end. Code that uses this service does not require any changes when migrating to WebAS 6.40.