cancel
Showing results for 
Search instead for 
Did you mean: 

JCo empty Parameters

Former Member
0 Kudos

Hi all,

I'm building a Java-Demo-System to interact with a SAP-System.

For the interaction I'm using JCo 3.0.

My code is based on the examples delivered in the JCo-Download Package.

The JCoClient works fine and I'm able to call a remote enabled Function Module I built to test.

Unfortunately the JCoServer has a little problem I can't find a solution for.

From a remote enabled Function Module I want to call a Function in the Java-Demo-System.

The Connection works fine, the Java-Programm can be called and the export Parameters from the Function Module are transfered correctly as Import-Parameters to the FunctionHandler-Method "handleRequest".

In the Method "handleRequest" I work with the Import-Parameter and at the end I set the value to the Export-Parameter.

No Error occurs, but in the Function Module the return-values are still empty.

Can anyone help me?

Best regards

Kirsten

Accepted Solutions (1)

Accepted Solutions (1)

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Kirsten,

you either did some coding error when setting the export values in Java where no one could help without knowing your code

- OR -

you are not doing a usual synchronous RFC but you are doing a transactional RFC instead.

A tRFC is processed asynchronously and does not return any result parameters.

Therefore one also needs to know how your ABAP CALL FUNCTION statement looks like.

Best regards,

Stefan


Former Member
0 Kudos

Hi Stefan,

thanks for your reply.

On the Java side I do the following steps:

  1. Collecting the properties as in the example
  2. Creating the Property-File
  3. Initializing the server with the created file (this.server = JCoServerFactory.getServer(this.getServerName());)
  4. Initializing the Throwable- and StateChanged - Listener
  5. Creating the Repository
    • The Repository gets an API-Class with the methods can be called from SAP (The code is atteched) 
    • A FunctionTemplate will be created for every method in the method getFunctionTemplate() (also in the attachment). In this Method an import- and an export- parameterlist will be filled. The importlist will be filled by the signatures of the methods. The exportlist is at the moment for testing and for every method the same.
  6. Starting the Server.

On the ABAP side I have this small function module:


FUNCTION Z_KO_CONNECT.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"----------------------------------------------------------------------

DATA:

      ltext TYPE STRING,

      TEXT TYPE STRING,

      TEXT2 TYPE STRING.

ltext = 'new'.

CALL FUNCTION 'TESTCONNECTION'

  DESTINATION 'DEMO'

EXPORTING

  TEXT = 'HALLOECHEN'

IMPORTING

  ltext = TEXT2.

WRITE 'ltext:' && ltext .

WRITE 'TEXT2:' && TEXT2 .

WRITE 'TEXT:' && TEXT .

ENDFUNCTION.

regards

Kirsten

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Kirsten,

SAP does not recommend to use static repositories.

This is a difficult task with lots of pitfalls.

Please use a standard dynamic repository instead, especially if you are a JCo beginner.

As you have already created an appropriate ABAP RFM please simply call

CALL FUNCTION 'Z_KO_CONNECT' DESTINATION 'DEMO' ...

at ABAP side.

At Java side, remove the static repository definition stuff and additionally supply the server property 'jco.server.repository_destination=<your_destination>' with targeting your AS ABAP system and using a userID that has repository access authorizations.

Please see note 460089 for the minimum authorization profile.

Best regards,

Stefan

Former Member
0 Kudos

Hi Stefan,

I got it

I did two things wrong.

At first the connection was wrong, it goes to another Gateway in our network therefore the function in Java could reached but the answer came never back.

The second failure I did the variables I defined in ABAP were Strings and in Java I defined the variables in the repository as Char. Even though I had this difference for all variables the import values were sent the right way only the export values made problems.

I tried to use no static repository respectivley custom repository but that's also not working and I have no idea how I can do it working. I built the server exactly like the examples and described on the sap help pages, but all 3 variants are sending no values and I get nullpointer exceptions when the parameters get read.

In the attachment I did the code I tested with. If you want to have a look at it and tell me if you see a point I can change that all variants can run. I'm still interested in all solutions and especially in the recommended ones.

Thank you for your help.

Kind regards

Kirsten

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Kirsten,

I'm glad that you finally got it working.

But what do you think what I meant with 'static repository'?

If my answer was not clear to you, you simply could have asked again...

With 'static repository' I meant repositories that do not query the RFC meta data from a connected AS ABAP system, so all type of repositories, which have static (local) RFC meta data defined.

A JCoCustomRepository usually IS a static repository. If you create the JCoLIstMetaData objects on your own, it holds static RFC meta data for all function templates and structures that you have added to it. This meta data is STATIC because it cannot change regardless to which AS ABAP system you would like to establish an RFC connection with. Maybe in some other AS ABAP system the remote function module definition is different and with your defined RFC meta data the call would fail then.

In addition to its unflexibility, defining static RFC meta data is a difficult and error prone task as there are many pitfalls, especially when it gets to more complex structures. Mixing CHAR and STRING types is only a very little one. For example, you have to consider certain memory alignments when calculating the field offsets.

The shipped server example just shows different approaches of working with JCo servers, every step in this example can be regarded as a complete program. For your needs I recommend to stick to the step1 and step2 parts. As you can see: it should work even without statically defining the meta data for STFC_CONNECTION, it should be fetched dynamically via a repository destination.

step3 is an example for handling tRFC calls and step4 is for working with a static repository.

Working with static repositories is really for the JCo experts only. It should be used with care for some desperate and very rare use cases only. And if using static repositories at all, I recommend to use the local repository storage feature (the load() and save() methods) instead of defining the RFC meta data programmatically on your own.

Best regards,

Stefan

Former Member
0 Kudos

Hi Stefan,

I understood it right, I think my english is sometimes a bit confusing

But that's the best explanation I've got to this topic, thank you.

My Problem with the non-static repository examples is that there are not working -.-

Example 1 and 2 are sending the error: "handler for Z_KO_CONNECT was not installed".

Example 3 can call the handler for Z_KO_CONNECT, but the parameterlists are null and I'm getting a NullPointerException.

I have to say I'm an ABAP noob, therefore I don't know if I have to do additional settings on the ABAP side.

Kind regards

Kirsten

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Kirsten,

my english is not perfect, too. I guess, we both could do better in german but with respect to the audience here, let's keep our conversation in english. By the way, your english is fine for me.

Regarding the error message "handler for Z_KO_CONNECT was not installed" please have a look into your coding. For the step1 example, the handler registration is done in lines 114 to 117. But you registered the StfcConnectionHandler instance as your handler for Z_KO_CONNECT which is very confusing. Why not creating an own class called ZKoConnectHandler instead?

And did you comment out step4 and execute the step1 method in the main() method before starting your Java example program? It would be also problematic if you were running multiple example programs simultaneously. So just start one and retry.

At ABAP side you need to activate your remote function module of course. Is it remote enabled? Please test it in transaction SE37 by calling it locally without a destination first. Does it work?

Best regards,
Stefan

Former Member
0 Kudos

Hi Stefan,

if you understand me it's all good

I've got it. All four examples are running.

I didn't realized that I had to define the parameters as import and export parameter for the whole function module and not only locally before I call the Java-Function.

Now it's clear to me that it couldn't work xD

Thank you very much for your help.

Kind regards

Kirsten

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Kirsten,

I'm glad to hear this.

Just one more thing regarding your attached program:

You are using the property 'jco.server.unicode' in your server configuration.

This property is a relict from JCo2 and not needed anymore with JCo3.

In JCo 3.0 a JCoServer can always handle both types of RFC requests - unicode and non-unicode. You do not have to decide which type of RFC communication your server implementation is for. The property 'jco.server.unicode' has no effect anymore and can be deleted.

Best regards,

Stefan


Answers (0)