Show TOC

Procedure documentationAdapting Connection Management Locate this document in the navigation structure

 

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.

Procedure

Perform the required changes in the code to adapt correctly to the connection management.

Example

The following example shows the changes in the code at connection setup:

Syntax Syntax

JCo 2.x

  1. JCO.addClientPool("FOO", 10, "000", "hugo", "*****", "EN", "appserver", "00");
  2. JCO.Repository repository = JCO.createRepository("MyRepository", SID);
  3. IFunctionTemplate template = repository.getFunctionTemplate("BAPI_COMPANY_GETLIST");
  4. if(template != null)
  5. {
  6.     JCO.Client client = null;
  7.     try
  8.     {
  9.         JCO.Function function = template.getFunction();
  10.         client = JCO.getClient("FOO");
  11.         client.execute(function);
  12.         JCO.ParameterList exports=function.getExportParameterList();
  13.         JCO.ParameterList tables=function.getTablesParameterList();
  14. 	
  15.         JCO.Structure bapiReturn = exports.getStructure("RETURN");
  16.         System.out.println("BAPI_COMPANY_GETLIST RETURN: " +
  17.                         bapiReturn.getString("MESSAGE"));
  18. 	
  19.     JCO.Table companies = tables.getTable("COMPANY_LIST");
  20.     if (companies.getNumRows()>0)
  21.     {
  22.             for (int i=0; i<companies.getNumRows(); i++)
  23.             {
  24.                 companies.setRow(i);
  25.                 System.out.println(companies.getString("COMPANY")+
  26.                                    ":  "+companies.getString("NAME1"));
  27.             }
  28.         }
  29.     }
  30.     catch (JCO.AbapException ex)
  31.     {
  32.         System.out.println("Caught a function module exception: \n" + ex);
  33.     }
  34.     catch (JCO.Exception ex)
  35.     {
  36.         System.out.println("Caught an exception: \n" + ex);
  37.     }
  38.     finally
  39.     {
  40.         JCO.releaseClient(client);
  41.     }
  42. }
End of the code.

Syntax Syntax

JCo 3.0

  1. JCoDestination foo= JCoDestinationManager.getDestination("FOO");
  2. JCoRepository repository = foo.getRepository();
  3. JCoFunctionTemplate template = repository.getFunctionTemplate("BAPI_COMPANY_GETLIST");
  4. if(template != null)
  5. {
  6.     try
  7.     {
  8.         JCoFunction function = template.getFunction();
  9.         function.execute(foo);
  10.         JCoParameterList exports=function.getExportParameterList();
  11.         JCoParameterList tables=function.getTablesParameterList();
  12.         JCoStructure bapiReturn = exports.getStructure("RETURN");
  13.         System.out.println("BAPI_COMPANY_GETLIST RETURN: " + 
  14. 	                    bapiReturn.getString("MESSAGE"));
  15. 	
  16.         JCoTable companies = tables.getTable("COMPANY_LIST");
  17. 	
  18.         if (companies.getNumRows()>0)
  19.         {
  20.             for (int i=0; i<companies.getNumRows(); i++)
  21.             {
  22.                 companies.setRow(i);
  23.                 System.out.println(companies.getString("COMPANY")+
  24.                                     ":  "+companies.getString("NAME1"));
  25.             }
  26.         }
  27.     }
  28.     catch (AbapException ex)
  29.     {
  30.         System.out.println("Caught a function module exception: \n" + ex);
  31.     }
  32.     catch (JCoException ex)
  33.     {
  34.         System.out.println("Caught an exception: \n" + ex);
  35.     }
  36. } 
End of the code.