A Brief Introduction to the JCo Server - Austin Sincock

来源:互联网 发布:php json base64 编辑:程序博客网 时间:2024/04/25 17:28

I am often asked for information as to how to call Java objects fromwithin an ABAP application. Although this functionality is included inthe JCo API, it is neither trivial nor easy to implement. In myupcoming book, Enterprise Java for SAP, I address the subject moreexhaustively and provide an in-depth tutorial application. However, forthe scope of this tip, I wanted to point you in the right direction forbuilding your own JCo server.

You may not know it, but everything you need to create a JCoserver is already available in the JCo download zip provided by SAP.The zip file includes several tutorial applications that show you howto build a sample server. Unfortunately, these examples are notdocumented very well, so the best way to learn the server is to playwith the actual Java classes.

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

You can now write an ABAP application that calls thisregistered server program at the RFC destination to access some basicJava object functionality from within SAP. Review the example files todetermine the appropriate import/export parameters and structures foreach Java class.

Unlike other types of JCo development, the JCo server APIrequires that you extend the JCO.Server base class within your ownserver class. JCO.Server provides access to the key methods that mustbe overriden to provide access from within the SAP system.

In order to implement the JCO.Server, you must override atleast the handleRequest() method. This describes how to handle importparameters from the ABAP application and processes export parametersfor return to the ABAP program. handleRequest() takes a JCO.Functioninstance that describes the function structure, similar to thestructure definition found in the SAP Function Builder. In fact, youcan create shell RFC structures in SAP to describe the externalinterface implemented in the JCo server.

You will also need to implement one of the JCO.Server's defaultconstructors. This constructor calls the JCO.Server superclass andloads the actual server based your specific SAP system parameters and aJCO.Repository. This repository can be generated by SAP, if yourexternal interface has been defined there, or you can create your ownJCO.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 inthe appropriate SAP system values to the server startup method. In theJCo examples, this startup class is implemented internally in eachclasses' main() method. Hopefully, this will point you in the rightdirection for deploying a JCo server. Again, this is a fairly complextopic that is not easily approached through a single tip. However,there are some nuggets of gold buried within the JCo download thatshould get you going with a JCo server development.

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

原创粉丝点击