Part 4: Creating a serialized RFC interface

Throughout the course of a development effort there are always times in which I want to test my JCo application but do not have live (online) access to an SAP system. I may be working from home, on a different customer site, or just experiencing a planned SAP outage, but not having SAP to run JCo makes the application pretty useless.

The quickest way to remedy this is to build the ability to use serialized RFC interfaces into your application. In Java, you can create serialized Java objects, whereby the full state of the object is written to the filesystem and can be re-read and re-used whenever necessary. In this case, I create and save a serialized RFC from a live SAP system, then reuse the serialized interface whenever I need to test the application.

The included application demonstrates how to create the serialized interface, then disconnect from SAP and use the serialized JCo function object as if it was STILL connected to an online SAP system.

import* ;

public class SerializeRFC {
 static final String[][] sapParams = { {"client", "000"}, {"user", "myUsername"}, 
{"passwd", "myPassword"}, {"lang", "EN"}, {"ashost", "mySapHost"}, {"sysnr", "00"}};
 static final String filePath = "c:/dev/JCofunction.ser";
 static final String interfaceName = "RFC_SYSTEM_INFO";
 public static void getInterface() {
  File fileOut = new File(filePath);
  try {
   System.out.println("Serializing online RFC function..");
   JCo.Client connection = JCo.createClient(sapParams);
   IRepository repository = new JCo.Repository("saprep", connection);
   JCo.Function function = repository.getFunctionTemplate(interfaceName).getFunction();
   ObjectOutputStream functionOut = new ObjectOutputStream(new FileOutputStream(fileOut));
  } catch (Exception ex) {
 private static JCo.Function retrieveInterface() {
  //Retrieve serialized RFC interface
  ObjectInputStream functionIn = null;
  JCo.Function function = null;
  try {
   File fileIn = new File(filePath);
   System.out.println("Retrieving offline RFC function...");
   functionIn = new ObjectInputStream(new FileInputStream(fileIn));
   function = (JCo.Function) functionIn.readObject();
  } catch (Exception ex){
  return function;
 public static void executeTestCase() {
  //Fake test case
  JCo.Function function = retrieveInterface();
  System.out.println("Executing test case for RFC System application...");
  JCo.Structure expStruct = function.getExportParameterList().getStructure("RFCSI_EXPORT");
  if (expStruct.getValue("RFCHOST").equals("mySapHost"))
   System.out.println("Test successful");
   System.out.println("Test failed");
 public static void main(String[] args) {


 Home: Introduction
 Part 1: Writing an RFC structure to XML
 Part 2: Generating metadata for an RFC structure
 Part 3: Load testing SAP with JCo
 Part 4: Creating a serialized RFC interface
 Review: Conclusion and more resources

This was first published in August 2005

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: