cancel
Showing results for 
Search instead for 
Did you mean: 

How can I retrieve a List of BAPIs with JCO?

Former Member
0 Kudos

Hello!

I want to retrieve a list of BAPIs in Java. Does anyone have a code sample how to do this with JCO and SWO_QUERY_API_METHODS?

Regards,

Jan

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hallo Jan,

you can use the RFC_FUNCTION_SEARCH FM instead. Use "BAPI_*" to get all the BAPIs available in the System.

Bye,

Sameer

Former Member
0 Kudos

Here's a solution. I use some of our own Utility-Methods but it shows the flow of control:

String bapi = "SWOQUERY_API_METHODS";

Object object = browser.createFunction(bapi);

JCO.Function _function = (JCO.Function) _object;

JCO.ParameterList _paramList = _function.getTableParameterList();

if (_paramList != null) {

System.out.println(_paramList.getMetaData("API_METHODS"));

browser.setValue(_function, "WITH_OBJECT_NAMES", "X", String.class, -1);

browser.execute(_function);

int size = browser.processTableSize(function, "API_METHODS", -1);

System.out.println(_size);

for (int i = 0; i < _size; i++) {

System.out.print(browser.getValue(_function, "API_METHODS.FUNCTION", i, String.class));

System.out.print(", ");

System.out.print(browser.getValue(_function, "API_METHODS.METHODNAME", i, String.class));

System.out.print(", ");

System.out.print(browser.getValue(_function, "API_METHODS.DESCRIPT", i, String.class));

System.out.println();

}

}

Former Member
0 Kudos

Hi Jan.

I was searching on internet about this topic and your answer is exactly what I was looking for. But I have a problem with this code, and this is that I don`t know how to declare browser. browser is an Object, a list, an array?, or what?

Can you help me, please?..

Thanks.

Diana.

Former Member
0 Kudos

Hi Diana,

I've written a small example here (refresh my rusty JCo!) which returns just the function names in a Vector.

Hope this helps,

Gregor



/**
 * Fetch a list of BAPIs
 * @author Gregor Brett
 */
import com.sap.mw.jco.*;
import java.util.*;

public class GetBapis
{
   private JCO.Client client;	
   private JCO.Repository repository;
   private Vector bapis;
   
   
   public GetBapis()
   {
      try
      {
         client = JCO.createClient("CLIENT","USERNAME","PASSWORD","EN","SERVERNAME","00");
         client.connect();
         repository = new JCO.Repository("Gregor", client);
		 IFunctionTemplate ftemplate = repository.getFunctionTemplate("SWO_QUERY_API_METHODS");
		 JCO.Function function = ftemplate.getFunction();
		 client.execute(function);
      	 JCO.Table table = function.getTableParameterList().getTable("API_METHODS");
      	 bapis = new Vector();
 
         do
         {
            JCO.Field functionName = table.getField("FUNCTION");
      	    bapis.add(functionName.getString());
         }
		 while(table.nextRow());
		 		 
      }
      catch(Exception e)
      {
         System.out.println("Error: " + e.getMessage());
         e.printStackTrace();
      } 
   }
   public Vector getBapiList()
   {
   	   return bapis;
   }
   
   public static void main(String[] args)
   {
   	   GetBapis gb = new GetBapis();
   	   Vector v = gb.getBapiList();
   	   System.out.println("Fetched " + v.size() + " BAPIs.");
   }
}