on 03-26-2011 5:42 PM
Hello,
i use JCo3. My Question is, how i can get all existing BAPIs from the Server?
regards,
Igor
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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
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.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.