cancel
Showing results for 
Search instead for 
Did you mean: 

Java RFC Connection: Step by step

Former Member
0 Kudos

Hi folks,

my first goal is to achieve a remote function call from Java to SAP or the other way.

My first attempt is a Java application which does a RFC to a SAP ABAP function that returns me some database data, but more about that later.

The first thing where i already fail is to build up a simple connection between Java and SAP.

I tried it with JCo v2.1.x and JCo v3.x (Which version should i prefer? are there advantages, disadvantages?)

Here are the two approaches:

{JCO v2.1.x}:

		
JCO.Client myConnection = JCO.createClient("001",
												   "***", 
												   "****", 
												   "DE", 
												   "***", 
												   "00");
myConnection.connect();
...
...

I get a "(103) RFC_ERROR_LOGON_FAILURE: Userid or password incorrect". I put in my normal SAP GUI account. Its not an admin account but i can create reports etc in the ABAP Editor.

I checked the spelling several time and it should be ok. Why does it say incorrect user or password?

Is this possible because of insufficient rights?

{JCo v3.x}:

I just tried the "StepByStepClient" example included in the sapjco3 download and i saw that every connect function begins with a "JCoDestination destination = JCoDestinationManager.getDestination(String);" line.

But what exactly does this getDestination function do? What string do i pass there? In the example is it JCoDestinationManager.getDestination("ABAP_AS_WITHOUT_POOL"); but then i get the error: ""(106) JCO_ERROR_RESOURCE: Destination ABAP_AS_WITHOUT_POOL could not be created:"..

Can anyone explain me how this works?

Thanks in advance!

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Ok thanks alot!

It works fine now. But is there any reason to use an older version of JCo (eg v2.1.x ?)

If not im gonna use the newest version since they work both now.

Thanks

Former Member
0 Kudos

ahhhh...if they both work.....they why to use an older version....

use 3.0....

good for you that they worked....

Former Member
0 Kudos

Hi,

as you already know my connection works now, but there are two more little questions that came up:

I'm using JCo 3.0 and this tutorial (http://www.vogella.de/articles/SAPJCo/article.html) to set up the connection.

As far as i know there are 2 methods to connect to an SAP system, via direct connection or using a connection pool.

But i dont know which method is used in this tutorial or how to change it afterwards.

I know from JCo 2.1.x that you have to close a connection after you initialized it but the author didnt do anything like this in his code.

Is this obsolete in JCo 3.0 or did he just forget it? (or maybe i've overlooked it)

Thanks

Former Member
0 Kudos

For getting a connection through connection pool...you need to look into below.....it very clearly explains your query...

http://help.sap.com/saphelp_nw04/helpdata/en/bc/eedf3d0eb8af5ee10000000a114084/content.htm

Also you can see in below example getting connection.....both with pool and without pool....

http://help.sap.com/saphelp_nwpi711/helpdata/en/48/634503d4e9501ae10000000a42189b/content.htm

Well in Above URL there is a complete example of JCO 3.0 and they too havnt' used Release method or kind of it.....

If you get one do let me know also..............

Former Member
0 Kudos

Just to add to that - with JCo 3.0 there is no need to explicitly open or close connections anymore, this is done by the framework. However, in case you need to maintain a specific connection with its context, there are ways to do that, have a look at the Javadoc for JCoContext, that should give a good explanation.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Felix,

I am student and beginner of ABAP. I am trying to send commands from SAP to Java. I tried searching for contents online but did not understand them since there are screenshots and I need to setup everything from start..

Can you help ?

Thanks

Sushil

Former Member
0 Kudos

Well as far as calling a RFC from java is concerned....below is code that worked fine for me.

JCO.Client connClient = null;
        IRepository mRepository;
	connClient = JCO.createClient("<SAP Client>","<UserId>","<Password>","EN","<Application server host name>","<system number>");
        try {
	connClient.connect();
	} catch (Exception ex)
	{
		ex.printStackTrace();
		System.exit(1);
	}
	mRepository = new JCO.Repository("Hell", connClient);
	JCO.Function strHELLO = mRepository.getFunctionTemplate("ZSAU_FM_ASSIGNMENT").getFunction();
	JCO.ParameterList importParam = strHELLO.getImportParameterList();
	importParam.setValue(val,"ZMATNR");
	try {
		connClient.execute(strHELLO);
	}catch (JCO.AbapException ex)
			{
			}

Make sure you have followed procedure mentioned under:

http://help.sap.com/saphelp_nw04/helpdata/en/47/80f671ee6e4b41b63c0fe46bd6e4f8/content.htm