Sunday, November 07, 2004

call outter java prog from sap

Setup and test SAP Java Connector outbound connectionGregor WolfCompany: Siteco Beleuchtungstechnik GmbHAug. 26, 2004 11:56 AMPermalink


Print
In the Java Programming forum Henric Boehm asked some questions:
Can someone help to configure the destination with SM59 in the R/3?
Do any ABAP codings exist for the examples 5 & 7?
Here are the answers.
Prerequisites
Installed SAP Java Connector (JCo). Can be downloaded here.
Java Development Kit (JDK) installed.
Authorisation to create a RFC destination in transaction SM59
Authorisation to create write a ABAP Program using SE80
Used System Information
Parameter
Value
Gateway Host
gateway
Gateway Service
sapgw00
Program ID
JCOSERVER01
Adopt Example5
When you extract the downloaded JCo ZIP file you will find a Java source file Example5.java in the directory demo. I've copied this file and named the copy "myExample5.java". Open this file with your favourite Editor and search and replace all strings "Example5" with "myExample5". In the next step we have make some changes in the source. First we reduce the number of connections to backend servers to 1. To do this go to line 153 and change it to:JCO.Server srv[] = new JCO.Server[1];
Next we adopt the connection data. This is done in line 174:srv[0] = new Server("gateway","sapgw00","JCOSERVER01",repository);
At last we have to comment out the second connection in line 177:// srv[1] = new Server("gwhost2","gwserv00","JCOSERVER02",repository);
Now save the file, compile and run it from the command line. The output should be:Server JCOSERVER01 changed state from [ STOPPED ] to [ STARTED ]
Server JCOSERVER01 changed state from [ STARTED ] to [ STARTED LISTENING ]
Create RFC destination
Start transaction SM59
Click the button "Create"
Enter the RFC destination JCO
Choose Connection Type T
Enter a Description JCo outbound
Press Enter
Go to the Technical settings tab
Choose Activation Type Registered Server Program
Enter Program ID JCOSERVER01
Save the connection
Click the button "Test connection"
The result of the Test connection should look like this:Connection test JCO

Connection type: TCP/IP connection

Logon: 702 msec
0 KB: 416 msec
10 KB: 332 msec
20 KB: 331 msec
30 KB: 366 msec
Run test program
To test the new connection and the JCo server we run this short test program:*&---------------------------------------------------------------------*
*& Report Z_JCO_TEST *
*& *
*&---------------------------------------------------------------------*
*& Test outbound JCO connection *
*& *
*&---------------------------------------------------------------------*
REPORT z_jco_test .
PARAMETERS: requtext LIKE sy-lisel.
DATA: echotext LIKE sy-lisel,
resptext LIKE sy-lisel.
CALL FUNCTION 'STFC_CONNECTION' DESTINATION 'JCO'
EXPORTING
requtext = requtext
IMPORTING
echotext = echotext
resptext = resptext.
WRITE: 'Echo Text: ', echotext.
WRITE: 'Response Text: ', resptext.
When you start the program you have to enter some text. Try "Hello World". The response should be:Test Outbound JCO connection

Echo Text:
HELLO WORLD
Response Text:
This is a response from myExample5.java
Gregor Wolf is the Webmaster of www.siteco.de and owner of Computerservice Wolf