In the next step, you can write a Java program that establishes a server connection to a SAP gateway.
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.Serverimplementation and start them with start().
public class MyFirstServer extends JCO.Server { /** * Create an instance of my own server * @param gwhost (gateway host) * @param gwserv (gateway service number) * @param progid (program id) * @param repository (repository used by the server to lookup the definitions of an inc) */ public MyFirstServer(String gwhost, String gwserv, String progid, IRepository repository) { super(gwhost,gwserv,progid,repository); }
/** * Overrides the default method. */ protected void handleRequest(JCO.Function function) { JCO.ParameterList input = function.getImportParameterList(); JCO.ParameterList output = function.getExportParameterList(); JCO.ParameterList tables = function.getTableParameterList();
System.out.println("handleRequest(" + function.getName() + ")"); if (function.getName().equals("STFC_CONNECTION")) { System.out.println(">>> request STFC_CONNECTION: " + input.getString("REQUTEXT")); output.setValue(input.getString("REQUTEXT"),"ECHOTEXT"); output.setValue("This is a response from MyFirstServer","RESPTEXT"); } } }
public class FirstExample { static MyFirstServer serverConnections[] = new MyFirstServer[3]; /** * Start the server */ public static void startServers() { JCO.addClientPool("POOL", 3, "000", "user" ,"password" , "EN", "abap_system" ,"00"); IRepository repository = JCO.createRepository("REP", "POOL"); for(int i = 0; I < serverConnections.length; i++) { // Server listens for incoming requests from system 1 // (Change gateway host, service, and program ID according to your needs) serverConnections [i] = new MyFirstServer ("gwhost", //gateway host, often the same as host "sapgw00", //gateway service, generally sapgw+<SYSNR> "JCOSERVER01", // corresponds to program ID defined in SM59 repository); serverConnections [i].start(); } public static void stopServers() { for(int i = 0; I < serverConnections.length; i++) { serverConnections [i].stop(); } public static void main(String[] args) { startServers() ; } } |
For a description of the Unicode connection, see:
· Server Connection to a Unicode Backend System