cancel
Showing results for 
Search instead for 
Did you mean: 

Get all existing BAPIs

Former Member
0 Kudos

Hello,

i use JCo3. My Question is, how i can get all existing BAPIs from the Server?

regards,

Igor

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello,

now i find this example, but the problem is that the example is for jco2 and i work with jco 3. I try to rewrite it for jco3, but i have some problems for example with the funtcition getField an etc. I need some help.

/**

  • 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.");

}

}

regards,

Igor

Former Member
0 Kudos

Hi,

Can you pls tell what error you are getting exactly. Also if you have JCO 3.0.6 downloaded fron https://websmp203.sap-ag.de/connectors then surely you will find sample examples.

Are you able to connect to the Server..?

Also give me some time..am out os station & will post the exact code for JCo 3.0.6

Thanks,

Arun

Former Member
0 Kudos

This is the exact coding that should be in Jco3.0


JCoRepository repository = destination.getRepository();
JCoFunctionTemplate template =
repository.getFunctionTemplate("FUNCTION_MOCULE");
JCoRecordMetaData structureDefinition =
repository.getStructureDefinition("MY_STRUCT");

JCoStructure structure=JCo.createStructure(structureDefinition);
structure.setValue(u201CTITLEu201D, u201CHello Worldu201D);
structure.setValue(1, u201CGood Morningu201D);
JCoFieldIterator iterator=structure.getFieldIterator();
while(iterator.hasNextField())
{
JCoField field=iterator.nextField();
System.out.println(u201CFieldValue: u201D+field.getString());
}
JCoFunction function = template.getFunction();
JCoParameterList tables=function.getTablesParameterList();
JCoTable tracks = tables.getTable("TRACKS");
if (!tracks.isEmpty())
{
for (int i=0; i<tracks.getNumRows(); i++)
{
tracks.setRow(i);
System.out.println(tracks.getString("ARTIST")+
": "+
tracks.getString("SONG"));
}
}
AbapException[] exceptions=function.getExceptionList();
if (exceptions!=null)
for (int i=0; i<exceptions.length(); i++)
System.out.println(u201CExceptionName: u201D+exceptions<i>.getKey());

You find the migration guide under https://websmp203.sap-ag.de/connectors

Paste ur mail id..will send that doc..

Thanks,

Arun

Former Member
0 Kudos

Thank you very much. Just a little bit later i will try you code.

In the example below i have problems with getField etc. just codes from jco2

And, yes i have a connection to server.

I will post later, if you code helps me)

regards,

Igor

Former Member
0 Kudos

Hello,

now i try this code:

public class CustomDestinationDataProvider

{

static class MyDestinationDataProvider implements DestinationDataProvider

{

private DestinationDataEventListener eL;

private Properties ABAP_AS_properties;

public Properties getDestinationProperties(String destinationName)

{

if(destinationName.equals("ABAP_AS") && ABAP_AS_properties!=null)

return ABAP_AS_properties;

return null;

//alternatively throw runtime exception

//throw new RuntimeException("Destination " + destinationName + " is not available");

}

public void setDestinationDataEventListener(DestinationDataEventListener eventListener)

{

this.eL = eventListener;

}

public boolean supportsEvents()

{

return true;

}

void changePropertiesForABAP_AS(Properties properties)

{

if(properties==null)

{

ABAP_AS_properties = null;

eL.deleted("ABAP_AS");

}

else

{

if(ABAP_AS_properties==null || !ABAP_AS_properties.equals(properties))

{

ABAP_AS_properties = properties;

eL.updated("ABAP_AS");

}

}

}

}

public static void main(String[] args) throws Exception

{

Properties connectProperties = new Properties();

connectProperties.setProperty(DestinationDataProvider.JCO_ASHOST, "xxx");

connectProperties.setProperty(DestinationDataProvider.JCO_SYSNR, "xx");

connectProperties.setProperty(DestinationDataProvider.JCO_CLIENT, "xxx");

connectProperties.setProperty(DestinationDataProvider.JCO_USER, "xxx");

connectProperties.setProperty(DestinationDataProvider.JCO_PASSWD, "xx");

connectProperties.setProperty(DestinationDataProvider.JCO_LANG, "en");

MyDestinationDataProvider myProvider = new MyDestinationDataProvider();

com.sap.conn.jco.ext.Environment.registerDestinationDataProvider(myProvider);

myProvider.changePropertiesForABAP_AS(connectProperties);

JCoDestination ABAP_AS = JCoDestinationManager.getDestination("ABAP_AS");

//Ping Test

/*ABAP_AS.ping();

System.out.println("ABAP_AS destination is ok");*/

System.out.println("Attributesxx:");

//System.out.println(ABAP_AS.getAttributes());

JCoRepository repository = ABAP_AS.getRepository();

JCoFunctionTemplate template = repository.getFunctionTemplate("SWO_QUERY_API_METHODS");

JCoFunction function = template.getFunction();

JCoParameterList tables=function.getTableParameterList();

JCoTable tracks = tables.getTable("API_METHODS");

if (!tracks.isEmpty())

{

for (int i=0; i<tracks.getNumRows(); i++)

{

tracks.setRow(i);

System.out.println(tracks.getString("FUNCTION"));

}

}

AbapException[] exceptions=function.getExceptionList();

if (exceptions!=null)

for (int i=0; i<exceptions.length; i++)

System.out.println("EX " + exceptions<i>.getKey());

}

}

i get this:

Attributesxx:

EX METHOD_NOT_API

EX METHOD_NOT_FOUND

EX METHOD_NOT_RELEASED

EX OBJTYPE_NOT_FOUND

EX PARAMETER_ERROR

and i don't understand what this means. I think i get Exception because i didnt have create any BAPIs, but its not so, because everybody have default BAPIs. What can i do? The aim is to get all BAPis)

regards

Igor

Former Member
0 Kudos

Hi,

I think instead of BAPI Name you can use *, inorder to retireve all BAPI`s. Am not sure whether it will work or not. Jus try

Here you go,

JCO.Repository repository=new JCO.Repository("MYSAP",mConnection);

IFunctionTemplate functemp=repository.getFunctionTemplate("BAPI Name");

JCO.Function func=functemp.getFunction();

mConnection.execute(func);

Thanks,

Arun V G.

Former Member
0 Kudos

Hello,

but i use JCo 3.0.5!!

regards,

Igor

Former Member
0 Kudos

Hi,

The codewhich i pasted can be used in Jco 3.0.6. I thinjk there is no version as JCo 3.0.5.

Another option is write a function module(BAPI) to retireve all the BAPI. I dont know how it will work.

Thanks,

Arun.