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 =
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
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
8. For any transactional calls (tRFC calls) you need to create a InteractionSpec object.
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:
In this case, MyConnFactory represents ConnectionFactory configured during the SAPJRA configuration (see SAP JRA Configuration on the SAP J2EE Application Server).
For more information on descriptors, please see:
● http://java.sun.com/dtd/web-app_2_3.dtd and