Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
gregorw
Active Contributor
13,766
In the Java DevelopmentHenric Boehm asked some Call java from ABAP:

  • 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 StepByStepServer.java


It seems that with SAP JCo 3 the structure of the examples changed. So if you're using that version you have to adopt the file StepByStepServer.java. Unfortunately the example doesn't come with the connection information. At Java Program for Creating a Server Connection you find that missing part. Alternatively you can create the .jcoDestination and .jcoServer files manually. Just adjust the JCO_PROGID to JCOSERVER01. That will match the RFC destination you create below.

Adopt Example5.java


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,
      rfctest TYPE TABLE OF rfctest,
      wa_rfctest TYPE rfctest.

wa_rfctest-rfcdata1 = requtext.
wa_rfctest-rfcdata2 = 'Hello World'.
APPEND wa_rfctest TO rfctest.

CALL FUNCTION 'RFC_PING'
  DESTINATION 'JCO'.

CALL FUNCTION 'STFC_CONNECTION'
  DESTINATION 'JCO'
  EXPORTING
    requtext = requtext
  IMPORTING
    echotext = echotext
    resptext = resptext
  TABLES
    rfctest  = rfctest.

WRITE: 'Echo Text: ', echotext.
WRITE: 'Response Text: ', resptext.

LOOP AT rfctest INTO wa_rfctest.
  WRITE: / 'rfcdata1: ', wa_rfctest-rfcdata1.
  WRITE: / 'rfcdata2: ', wa_rfctest-rfcdata2.
ENDLOOP.

When you start the program you have to enter some text. Try "Hello World". The response should be:

 
SAP Java Connector Outbound Connection Test

Echo Text:
TEST
Response Text:
This is a response from myExample5.java
rfcdata1:  TEST
rfcdata2:  Hello World

Security settings


It can happen that you will face the error message RFCIO_ERROR_REGISTRATION_DENIED written to the dev_jco_rfc.trc file. I was able to solve this by following Control the Registration of External Programs in the Gateway.
39 Comments
Labels in this area