Code to perform RFC Lookups. Compile this code and upload it in imported archives.

In Interface Mapping, Select this java mapping.

Source should be RFC request Interface and Target should be RFC Response Interface.

Please change the code marked in pink to your respective Business System and Communication Channel.

Do not forget to create the same in ID and activate them.

 //Code Begins

package com.ibis.mapping.lookup.rfc;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

import com.sap.aii.mapping.api.AbstractTrace;
import com.sap.aii.mapping.api.MappingTrace;
import com.sap.aii.mapping.api.StreamTransformation;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.lookup.Channel;
import com.sap.aii.mapping.lookup.LookupException;
import com.sap.aii.mapping.lookup.LookupService;
import com.sap.aii.mapping.lookup.Payload;
import com.sap.aii.mapping.lookup.RfcAccessor;
import com.sap.aii.mapping.lookup.XmlPayload;

public class RFCLookup implements StreamTransformation
{
 public Map param = null;

 public static void main(String[] args)
 {
  try
  {
   InputStream in = new FileInputStream(new File(
     "TestFile.xml"));
   OutputStream out = new FileOutputStream(
     new File(
       "Test.xml"));

   RFCLookup rfcLookup = new RFCLookup();
   rfcLookup.execute(in, out);
   

  }
  catch (Exception e)
  {
   System.out.println("ERROR IS :" + e.getMessage());
  }

 }

 public void execute(InputStream inputStream, OutputStream outputStream)
   throws StreamTransformationException
 {
  

  MappingTrace importanttrace;
  importanttrace = (AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE );
  RfcAccessor accessor = null;

  try
  {
   
   // 1. Determine a channel (Business system, Communication channel)
   Channel channel = LookupService.getChannel("BS", "Comm_Channel");
   
   // 2. Get a RFC accessor for a channel.
   accessor = LookupService.getRfcAccessor(channel);
   importanttrace.addInfo("Accessor Looked up.");
   
   // 4. Create xml payload from the inputStream
   XmlPayload payload = LookupService.getXmlPayload(inputStream);
   importanttrace.addInfo("Input stream payload fetched");
   
   // 5. Execute lookup.
   Payload result = accessor.call(payload);
   importanttrace.addInfo("Called the RFC");

   // 6. Get the lookup response in new InputStream
   InputStream in = result.getContent();
   importanttrace.addInfo("got output");
   // 7. Transfer the inputstream into outputstream
   
   
   
   byte[] buffer = new byte[1024];
   for (int read = in.read(buffer); read > 0; read = in.read(buffer))
   {
    outputStream.write(buffer, 0, read);
    outputStream.write('\n');
   }
   outputStream.flush();
  }
  catch (LookupException e)
  {
   importanttrace.addWarning("Error while lookup " + e.getMessage());
  }
  catch (IOException e)
  {
   importanttrace.addWarning("Error " + e.getMessage() );
  }
  finally
  {
   
   // 8. close the accessor in order to free resources.
   if (accessor != null)
   {
    try
    {
     accessor.close();
    }
    catch (LookupException e)
    {
      importanttrace.addWarning("Error while closing accessor " + e.getMessage() );
    }
   }
  }
  

 }

 public void setParameter(Map param)
 {
  this.param = param;  
  if (param == null)
  {
          this.param = new HashMap();
     }


 }

}

//Code Ends