Problem solve Get help with specific problems with your technologies, process and projects.

Building an SAP interface lookup tool with JCo

Have you ever wanted to do a quick lookup on an RFC or BAPI interface in SAP without going through the SAP GUI? Here's how!

Have you ever wanted to do a quick lookup on an RFC or BAPI interface in SAP without going through the SAP GUI? You might be working with an external application and need to check quickly for a field name or structure definition. JCo makes it fairly simple to develop a client-side tool to retrieve an interface definition from SAP.

This tip gives the code for a very basic interface lookup tool. The tool takes the name of an RFC or BAPI, retrieves the metadata structure for that interface, and builds an XML definition and an HTML table. The XML definition could be used to populate and push a call from an external system and the HTML table can be used to check a field name and its specific characteristics.

Above and beyond its utility, this tool demonstrates some of the extended functionality available through the JCo API. See if you can come up with some other uses for the XML/HTML generation function within the JCo API.


public class Rfc2Xml {
 private static JCO.Client theConnection;
 private static IRepository theRepository;

 public static void main(String[] args) {

  String functName = null;
// Change this value to save the files in a different directory
  String directory = "c:\temp\";
  String filename = null;

  if (args.length <= 0) {
   System.out.println("No function name entered");
   functName = args[0];

  filename = directory + functName;

  theConnection = JCO.createClient(
                        "system number");

  JCO.Function function = getFunction(functName);
// Here are the methods that actually write the XML and HTML
  function.writeHTML(filename + ".html");
  function.writeXML(filename + ".xml");

  System.out.println("HTML and XML files have been written to: " + filename);

 private static void retrieveRepository() {
  try {
   theRepository = new JCO.Repository("saprep", theConnection);
  catch (Exception ex)
   System.out.println("failed to retrieve repository");
 private static JCO.Function getFunction(String name) {
  try {
   return theRepository.getFunctionTemplate(name.toUpperCase()).getFunction();
  catch (Exception ex) {
     return null;

Execute this Java class from the command line, passing in the name of the RFC/BAPI as the single argument:


Author Austin Sincock is a freelance Java/SAP consultant who contributes regularly to Web and print journals. He can be reached at Check out his book Enterprise Java for SAP Building an SAP Interface Lookup Tool with JCo

Dig Deeper on SAP UX

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.