Skip to Content

I was developing a J2EE application that was made up of a Java, EJB and EAR DCs on the NetWeaver Web Application 6.40 server that required calling an RFC from an R3 system. I found several examples as to how this could be achieved, but they all had the connection details hard coded into the code!

This blog will show a real world example on how to use the SAP Enterprise Connector without hard coding the JCO connection details in a NetWeaver 2004 (6.40) environment.  Therefore, allowing an application to be deployed to multiple runtime systems without having to make any changes.

The SAP Enterprise Connector is a NetWeaver Developer Studio (NWDS) tool that allows you to create helper classes called a Java proxy for calling RFCs. The Java proxy hides native JCO calls, guarantees type-secure data access and handles Unicode conversion. In other words, the Java proxy acts as a layer of abstraction and simplifies the calling of RFCs through JCOs in J2EE applications.

Destination: Visual Administrator

Destination services can be setup on the NetWeaver Web Application server that allow applications to establish connections to other services like RFCs.  Creating a RFC destination in Visual Administrator will allow applications to call RFCs without hard coding the connection details in the code. 

To create a new RFC Destination, start the Visual Administrator. Then:

  • Navigate to Server -> Services -> Destinations.
  • Select RFC and click on New.
  • Enter a Destination Name (eg ERPR3) and the required information to connect to the remote system.
  • Click on the “Save and Test” button to save the settings and test the connection.

My J2EE application consists of a Java, EJB and EAR DCs and the Java DCs must call the RFC. In order to call an RFC through a JCO, several used DCs need to be added to the Java DC.

From the SAP_JTECHS software component, the following DCs need to be added


From the SAP_JEE software component, the following DCs need to be added

  • security.class
  • tc/sec/destinations/interface

After adding these DCs, the Used DCs of the Java DC will look as follows:
Used DCs

In order to avoid runtime errors, the following references must be added to the application-j2ee-engine.xml in the EAR DC.

  • tc/sec/destinations/interface

References added to application-j2ee-engine.xml

Finally, create a new package in the Java DC for the Java proxy class that will be created.

Now that everything is setup, the Java proxy can be created using the SAP Enterprise Connector tool in the NWDS. Select the newly created package and then navigate to File -> New -> Other -> SAP Connectivity -> SAP Enterprise Connector (A step by step example can be seen here).

Enter a name for the proxy class that will be generated. In this example, I entered “LotCharacteristics”. Next, enter the logon details, select the RFC module and select “Finish”.

The following classes are generated by SAP Enterprise Connector tool.

The following code, taken from, will access the “ERPR3” RFC destination that was created in Visual Administrator. This piece of code replaces the need to hard code the login details.

final InitialContext ctx = new InitialContext();
final DestinationService dstService = (DestinationService)ctx.lookup(DestinationService.JNDI_KEY);
if (dstService == null)
  throw new NamingException("Destination Service not available");
RFCDestination dst;
// get the ERPR3 destination created in visual administrator
dst = (RFCDestination) dstService.getDestination("RFC", "ERPR3");
Properties jcoProperties = dst.getJCoProperties();  

Next, you need to establish either a direct or pooled RFC connection. In this example, a direct connection is established. For a pooled connection, see

//Establish a direct connection
JCO.Client client = JCO.createClient(jcoProperties);

Finally, call the RFC.

Z_Rfc_Lot_Characteristics_Input input = new Z_Rfc_Lot_Characteristics_Input();
LotCharacteristics_PortType proxy = new LotCharacteristics_PortType();
Z_Rfc_Lot_Characteristics_Output output = proxy.z_Rfc_Lot_Characteristics(input);

The code in this example needs to be placed within a try/catch block as several exceptions are thrown.

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

  1. Former Member Post author
    I had a doubt,

    When you are talking about a Java, EJB and EAR Dc’s do you refer to 3 proyects in NWDS?

    and how do you integrate the javsa dc with the ejb?

    or how its compiled

    Thnx For Your Attention


Leave a Reply