Show TOC

Procedure documentationJava Program for Establishing a Server Connection Locate this document in the navigation structure

 

In the next step, you can write a Java program that establishes a server connection to a SAP gateway.

Procedure

To do this, you need to:

  • extend the JCO.Server class

  • implement a constructor that passes on the required parameters to the JCO.Server superclass such as Gateway Host, Gateway Service, Program ID and Repository.

  • overwrite the protected void method handleRequest(JCO.Function function) and implement the coding that is executed when the call is received.

  • create various instances for your JCO.Server implementation and start them with start().

Example

Syntax Syntax

  1. public class MyFirstServer extends JCO.Server {
  2.     /**
  3.      *  Create an instance of my own server
  4.      *  @param gwhost (gateway host)
  5.      *  @param gwserv (gateway service number)
  6.      *  @param progid (program id)
  7.      *  @param repository (repository used by the server to lookup the 
  8.        definitions of an inc)
  9.      */
  10.     public MyFirstServer(String gwhost, String gwserv, 
  11.                          String progid, IRepository repository) {
  12.                super(gwhost,gwserv,progid,repository);
  13.     }
  14.     /**
  15.      *  Overrides the default method.
  16.      */
  17.     protected void handleRequest(JCO.Function function) {
  18.         JCO.ParameterList input  = function.getImportParameterList();
  19.         JCO.ParameterList output = function.getExportParameterList();
  20.         JCO.ParameterList tables = function.getTableParameterList();
  21.         
  22.         System.out.println("handleRequest(" + function.getName() + ")");
  23.         if (function.getName().equals("STFC_CONNECTION")) {
  24.             System.out.println(">>> request STFC_CONNECTION: " + input.getString("REQUTEXT"));
  25.             output.setValue(input.getString("REQUTEXT"),"ECHOTEXT");
  26.             output.setValue("This is a response from MyFirstServer","RESPTEXT");
  27.         }
  28.     }
  29. }
  30. public class FirstExample {
  31.     static MyFirstServer serverConnections[] = new MyFirstServer[3];
  32.     /**
  33.      *  Start the server
  34.      */
  35.     public static void startServers()  {
  36.       JCO.addClientPool("POOL",  3, "000", "user" ,"password" , "EN", 
  37.                                      "abap_system" ,"00");
  38.        IRepository repository = JCO.createRepository("REP", "POOL");
  39.        for(int i = 0; I < serverConnections.length; i++) {
  40.            // Server listens for incoming requests from system 1
  41.            // (Change gateway host, service, and program ID according to your
  42.               needs)
  43.            serverConnections [i] = new MyFirstServer 
  44.                              ("gwhost",  //gateway host, often the same as host
  45.                               "sapgw00", //gateway service, generally sapgw+<SYSNR>
  46.                               "JCOSERVER01", // corresponds to program ID defined in SM59
  47.                               repository);
  48.            serverConnections [i].start();
  49.     }
  50.     public static void stopServers()  {
  51.        for(int i = 0; I < serverConnections.length; i++) {
  52.            serverConnections [i].stop();
  53.     }
  54.     public static void main(String[] args)    {
  55.               startServers() ;
  56.     }
  57. }
End of the code.

More Information

For a description of the Unicode connection, see: