Show TOC Start of Content Area

This graphic is explained in the accompanying textClient Programming Model  Locate the document in its SAP Library structure

The following example describes a client programming model that you can use in Java EE applications (Servlets, EJB, etc):


       1.      Set a context for the Connection Factory which was configured during SAPJRA instance configuration (see previous section. Here the name could be MyConnFactory):


InitialContext initialcontext = new InitialContext();

ConnectionFactory connectionfactory =

(ConnectionFactory) initialcontext.lookup("java:comp/env/MyConnFactory");


       2.      Request a connection handle:

Connection connection = connectionfactory.getConnection();


       3.      Create a RecordFactoryobject to get a metadata description of the Remote Function Modules (RFM), that you will be calling:

RecordFactory recordFactory = connectionfactory.getRecordFactory();


       4.      Create Record objects containing all necessary information about theRFM.

MappedRecord input =recordFactory.createMappedRecord("NameOfYourRFM");

This input object can be filled with business data.

For example, if your input structure has a String field “MyBank”, you may set it by



       5.      Create an interaction object to make a call to an SAP system where you can send your business data and receive data back:

Interaction interaction = connection.createInteraction();


       6.       Then you execute the call itself using the method

           public Record execute(InteractionSpec interactionSpec, Record input)


The input parameter in the method execute(interactionSpec, input) should be of type  MappdRecord. The return object output in this method is also always of type MappedRecord.

       7.      For any synchronous calls  you have to pass null for interactionSpec, like

     MappedRecord output = (MappedRecord) interaction.execute(null, input);


       8.      For any transactional calls (tRFC calls) you need to create a  InteractionSpec object.

InteractionSpec interactionSpec =

          ((InteractionSpecFactory) connectionFatory).createInteractionSpec();

          And pass this object within the  method execute, like

     interaction.execute(interactionSpec, input);


There is no output evaluation, since the tRFC doesn’t return any output.

If the InteractionSpec doesn't contain a TID, the new TID is created.

On failure the caller should use the same InteractionSpec object to repeat the call.

If you use a new InteractionSpec instance in the next call, this will generate a new Transaction ID. This new call will then be considered as an independent call accordingly.


       9.      Add the description of this ConnectionFactory to your standard descriptor web.xml (if you access the factory from a servlet) or ejb-jar.xml (if you access the factory from EJB) to allow your application to access a specified ConnectionFactory:


        <res-ref-name> MyConnFactory </res-ref-name>





In this case, MyConnFactory  represents ConnectionFactory configured during the SAPJRA configuration (see SAP JRA Configuration on the SAP J2EE Application Server).


Further Information

      Transactions for the Client Programming Model

      Security for the Client Programming Model

For more information on descriptors, please see: and




End of Content Area