Tip

Build a Java Web application for SAP right now

So you can't wait for SAP to officially release a Java application server and need to start building Web applications for SAP now. A great place to start your development is with Apache's open source Java server, Tomcat. By starting your Java development now you not only hone your skills but are also building code that can easily be ported to SAP's Web Application Server when it supports Java.

First things first. You need to get the application server. Point your browser at: http://jakarta.apache.org/tomcat/index.html and download the latest release of Tomcat (4.0). Next you need to download SAP's Java connector JCo from http://service.sap.com/connectors (you will need your OSS ID and password to get in).

Now that we have the goods, we need to install them into the right locations. Run the Tomcat install script and install it into the location of your choice (e.g. c:tomcat). Drill into the Tomcat directory to find the 'commonlib' directory (c:tomcatcommonlib). Open the JCo zip and extract the file jco.jar to the tomcatcommonlib directory. Don't forget to extract the three dlls that come with JCo into <Windows root directory>system32 (e.g. c:winntsystem32). That's all there is to it. If you are running a flavor of UNIX as your desktop, please refer to the documentation included with JCo for installation instructions. We can now access SAP through JCo with any application running in the Tomcat server.

The next step is to create

    Requires Free Membership to View

a basic JSP (Java Server Page) that allows us to access SAP. I used the example code that comes with JCo. The original can be found under: <JCo install dir>:demoexample1.java

First create a directory called 'testapp' under the tomcatwebapps directory (e.g. c:tomcatwebappstestapp). Then create a text file called 'sysinfo.jsp' (don't forget the .jsp file extension). Cut and paste the source code from the demo into 'sysinfo.jsp', change the system information in the code to reflect your specific SAP configuration, and save it. Run the 'startup.bat' script in the tomcat root directory. Finally point your browser at http://localhost/testapp/sysinfo.jsp. If all goes well, you should see some rather exciting SAP system information displayed in your Web browser. This may not seem like much, but we have laid the groundwork for quickly developing Web applications for SAP. Enjoy!


Author Austin Sincock is product manager for ROBUSTA(tm), Gamma Enterprise Technologies Web sales solution for SAP.


<%@ page language="java" %>

<%@page import="com.sap.mw.jco.*"%>

<HTML>
<BODY class=bg MARGINWIDTH="0" MARGINHEIGHT="0" LEFTMARGIN="0" TOPMARGIN="0" BGCOLOR="#FFFFFF">
<%
 // The MySAP.com system we gonna be using
 String SID = "R3";

 // The repository we will be using
 IRepository repository;

  try {
   // Add a connection pool to the specified system
   JCO.addClientPool(SID,    // Alias for this pool
        10,    // Max. number of connections
        "100",   // SAP client 
        "username",  // userid 
        "XXXXXX",  // password 
        "EN",     // language
        "appserver",// host name
        "00");

   // Create a new repository
   repository = JCO.createRepository("MYRepository", SID);
  }
  catch (JCO.Exception ex) {
   System.out.println("Caught an exception: \n" + ex);
  }
  repository = JCO.createRepository("MYRepository", SID);

  try {

   // Get a function template from the repository
   IFunctionTemplate ftemplate = repository.getFunctionTemplate("RFC_SYSTEM_INFO");

   // Create a function from the template
   JCO.Function function = new JCO.Function(ftemplate);

   // Get a client from the pool
   JCO.Client client = JCO.getClient(SID);

   // We can call 'RFC_SYSTEM_INFO' directly since it does not need any input parameters
   client.execute(function);

   // The export parameter 'RFCSI_EXPORT' contains a structure of type 'RFCSI'
   JCO.Structure s = function.getExportParameterList().getStructure("RFCSI_EXPORT");

   // Use enumeration to loop over all fields of the structure

%>
<H1>System info for <%= SID %></H1>

--------------------
<BR>
<%

   for (JCO.FieldIterator e = s.fields(); e.hasMoreElements(); ) {
    JCO.Field field = e.nextField();
%>

<%= field.getName() %> : <%= field.getString() %><BR>

<%
   }//for
%>
<BR>
<%
   // Release the client into the pool
   JCO.releaseClient(client);
  }
  catch (Exception ex) {
   System.out.println("Caught an exception: \n" + ex);
  }
%>


</BODY>
</HTML>

This was first published in March 2002

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.