I am often asked how to call Java objects from within an ABAP application. Although this functionality is included...
By submitting your personal information, you agree that TechTarget and its partners may contact you regarding relevant content, products and special offers.
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, 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 email@example.com. Check out his upcoming book Enterprise Java for SAP