Connection management has been modified completely for the new JCo API. Until now the connection setup at the client side has used different JCo classes as a direct connection or Connection Pool.
In the new JCo API, connection management is no longer a task for the client application, but is managed centrally by a destination model.
A Destination Manager transfers a logical destination to the client, who in turn can trigger a certain function to be carried out on this destination.
This connection model means that you can avoid a high level of configuration.
Perform the required changes in the code to adapt correctly to the connection management.
The following example shows the changes in the code at connection setup:
Syntax
JCo 2.x
JCO.addClientPool("FOO", 10, "000", "hugo", "*****", "EN", "appserver", "00");
JCO.Repository repository = JCO.createRepository("MyRepository", SID);
IFunctionTemplate template = repository.getFunctionTemplate("BAPI_COMPANY_GETLIST");
if(template != null)
{
JCO.Client client = null;
try
{
JCO.Function function = template.getFunction();
client = JCO.getClient("FOO");
client.execute(function);
JCO.ParameterList exports=function.getExportParameterList();
JCO.ParameterList tables=function.getTablesParameterList();
JCO.Structure bapiReturn = exports.getStructure("RETURN");
System.out.println("BAPI_COMPANY_GETLIST RETURN: " +
bapiReturn.getString("MESSAGE"));
JCO.Table companies = tables.getTable("COMPANY_LIST");
if (companies.getNumRows()>0)
{
for (int i=0; i<companies.getNumRows(); i++)
{
companies.setRow(i);
System.out.println(companies.getString("COMPANY")+
": "+companies.getString("NAME1"));
}
}
}
catch (JCO.AbapException ex)
{
System.out.println("Caught a function module exception: \n" + ex);
}
catch (JCO.Exception ex)
{
System.out.println("Caught an exception: \n" + ex);
}
finally
{
JCO.releaseClient(client);
}
}
Syntax
JCo 3.0
JCoDestination foo= JCoDestinationManager.getDestination("FOO");
JCoRepository repository = foo.getRepository();
JCoFunctionTemplate template = repository.getFunctionTemplate("BAPI_COMPANY_GETLIST");
if(template != null)
{
try
{
JCoFunction function = template.getFunction();
function.execute(foo);
JCoParameterList exports=function.getExportParameterList();
JCoParameterList tables=function.getTablesParameterList();
JCoStructure bapiReturn = exports.getStructure("RETURN");
System.out.println("BAPI_COMPANY_GETLIST RETURN: " +
bapiReturn.getString("MESSAGE"));
JCoTable companies = tables.getTable("COMPANY_LIST");
if (companies.getNumRows()>0)
{
for (int i=0; i<companies.getNumRows(); i++)
{
companies.setRow(i);
System.out.println(companies.getString("COMPANY")+
": "+companies.getString("NAME1"));
}
}
}
catch (AbapException ex)
{
System.out.println("Caught a function module exception: \n" + ex);
}
catch (JCoException ex)
{
System.out.println("Caught an exception: \n" + ex);
}
}