cancel
Showing results for 
Search instead for 
Did you mean: 

how to establish a JCO client connection

Former Member
0 Kudos

I have made a java class which I call from an “User defined Function”.

The java Class has to establish a JCO client in order to connect to an ABAP module.

The normal described way to establish a JCO client is:

JCO.Client client = JCO.createClient(sapClient, userName, password, language, hostName, systemNumber );

But if the ABAP module I want to access is on the same SAP system, is it then necessary to make this logon ?

And how can the client then be created ?

Further this code is not good !!!

What if the parameters changes, then we will have to make the same changes in our java code as well.

<b><u>Java Class :</u></b>

public class GetNumber

{

public static String getNumber(String Customer, String Invoice){

// input

String NR_ID = Customer;

String InvoiceNo = Invoice;

// output

String NUMBER = "";

String sapClient = "XXX";

String hostName = "xx.zz.cc.mm";

String systemNumber = "XX";

String userName = "UUUUUU";

String password = "XXXXXX";

String language = "EN";

try

{

<b><i>JCO.Client client = JCO.createClient(sapClient, userName, password, language, hostName, systemNumber );</i></b>// connect to SAP

client.connect();

// create repository

JCO.Repository mRepository = new JCO.Repository( "GeneratedFileNumber", client );

JCO.Function function = null;

try

{

function = mRepository.getFunctionTemplate("ABAP_module").getFunction();

}

catch (Exception e)

{

}

// Obtain parameter list for function

JCO.ParameterList input = function.getImportParameterList();

// Pass function parameters

input.setValue(InvoiceNo, "INPUTNO");

input.setValue(NR_ID, "INPUT_ID");

function.setImportParameterList(input);

try {

client.execute(function);

}

catch (Exception e)

{

}

// Disconnect to SAP

client.disconnect();

}

catch (Exception e)

{

}

return function.getExportParameterList().getValue("NUMBER").toString();

}

Accepted Solutions (1)

Accepted Solutions (1)

Andrzej_Filusz
Contributor
0 Kudos

Hi Frank!

You can use properties file for storing values like login and password, etc. In that case, you won't have to recompile your code every time these values will be changed.

Look at API for java.util.Properties class please.

Regards,

Andrzej

Former Member
0 Kudos

i found a way to let the SLD do this <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/2ce854ed-0701-0010-deb5-ffd61d73fd9f">see here</a>

But is it neccesary to make the logon, when the ABAP module i call is placed on the same SAP system ?

robertot4s
Active Participant
0 Kudos

Hi,

Maybe you could create an RFC destination in SM59 and access it with:

public static JCO.Client createClient(java.lang.String gwhost, java.lang.String gwserv, java.lang.String tpname)

regards,

RCV

Answers (0)