An introduction to the JCo server

An introduction to the JCo server

I am often asked how to call Java objects from within an ABAP application. Although this functionality is included in the JCo API, it is not easy to implement. My upcoming book Enterprise Java for SAP provides an in-depth tutorial application. However, in this tip, I will point you in the right direction for building your own JCo server.

Everything you need to create a JCo server is already available in the JCo download zip provided by SAP. The zip file includes several tutorial applications that show you how to build a sample server. Unfortunately, these examples are not documented very well, so the best way to learn the server is to play with the actual Java classes.

To start with, check out the directory <JCO_INSTALL>/demo for all of the included tutorial Java class files. The files you are interested in are Example5.java and Example7.java. Before running these applications, you must create an RFC destination in SAP that uses a registered server program called 'JCOSERVER01'. Once this destination exists, compile and execute one of these classes from the command line and JCOSERVER01 will register itself to the specified RFC destination.

You can now write an ABAP application that calls this registered server program at the RFC destination to access some basic Java object functionality from within SAP. Review the example files to determine the appropriate import/export parameters and structures for each Java class.

Unlike other types of JCo development,

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

the JCo server API requires that you extend the JCO.Server base class within your own server class. JCO.Server provides access to the key methods that must be overriden to provide access from within the SAP system.

In order to implement the JCO.Server, you must override at least the handleRequest() method. This describes how to handle import parameters from the ABAP application and processes export parameters for return to the ABAP program. handleRequest() takes a JCO.Function instance that describes the function structure, similar to the structure definition found in the SAP Function Builder. In fact, you can create shell RFC structures in SAP to describe the external interface implemented in the JCo server.

You will also need to implement one of the JCO.Server's default constructors. This constructor calls the JCO.Server superclass and loads the actual server based your specific SAP system parameters and a JCO.Repository. This repository can be generated by SAP, if your external interface has been defined there, or you can create your own JCO.Repository with only the external interfaces used by the server. See the JCo examples for a demonstration of custom JCO.Repositorys.

Finally, you will need a server startup class that passes in the appropriate SAP system values to the server startup method. In the JCo examples, this startup class is implemented internally in each classes' main() method. Hopefully, this will point you in the right direction for deploying a JCo server. Again, this is a fairly complex topic that is not easily approached through a single tip. However, there are some nuggets of gold buried within the JCo download that should get you going with a JCo server development.

Author Austin Sincock is a freelance Java/SAP consultant who contributes regularly to Web and print journals. He can be reached at austin@opensourceguru.com. Check out his upcoming book Enterprise Java for SAP

This was first published in May 2003

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.