cancel
Showing results for 
Search instead for 
Did you mean: 

connect ABAP function module with Java

Former Member
0 Kudos

how to connect a function module of ABAP with java?

Whenever i execute a function module, i want to show the output of that function module using java.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi ,

You can also have a Jco connection with the RFC that you have in the ABAP end. Have a look at this link

<http://help.sap.com/saphelp_nw2004s/helpdata/en/cb/072642c9dedd2ce10000000a1550b0/frameset.htm><a href="http://help.sap.com/saphelp_nw2004s/helpdata/en/cb/072642c9dedd2ce10000000a1550b0/frameset.htm">http://help.sap.com/saphelp_nw2004s/helpdata/en/cb/072642c9dedd2ce10000000a1550b0/frameset.htm</a>.

Best Regards, Giri

Former Member
0 Kudos

Hi,

You need to use <b>SAP.Functions</b> class to connect to a ABAP Function module (RFC) from any external system. Have a look at the weblog <b>/people/nathan.jones3/blog/2006/10/26/rfc-connections-to-sap-with-yahoo-widgets You need to code on similar lines.

hope this helps.

best regards, Giri

Former Member
0 Kudos

hi,

can u help me with an example code.

Former Member
0 Kudos

Hi Abie,

you can download the Java Connector JCO from here:

https://websmp206.sap-ag.de/~sapidb/011000358700007415502002E

Choose your achitecture and download the file.

In this archive you can find a lot of examples of java connections to RFC.

Here an example:

import com.sap.mw.jco.*;

/**

  • Example1 - start a simple call with static metadata definition

*

  • @version 1.0

  • @author SAP AG, Walldorf

*/

public class Example1 {

public static void main(String[] argv)

{

JCO.Client client = null;

try {

// Print the version of the underlying JCO library

System.out.println("\n\nVersion of the JCO-library:\n" +

"----


\n" + JCO.getMiddlewareVersion());

// Create a client connection to a dedicated R/3 system

client = JCO.createClient( "000", // SAP client

"johndoe", // userid

"*****", // password

"EN", // language

"appserver", // host name

"00" ); // system number

// Open the connection

client.connect();

// Get the attributes of the connection and print them

JCO.Attributes attributes = client.getAttributes();

System.out.println("Connection attributes:\n" +

"----


\n" + attributes);

boolean is_backend_unicode = attributes.getPartnerCodepage().equals("4102") ||

attributes.getPartnerCodepage().equals("4103");

// Create metadata definition of the input parameter list

JCO.MetaData input_md = new JCO.MetaData("INPUT");

input_md.addInfo("REQUTEXT", JCO.TYPE_CHAR, 255, 255 * (is_backend_unicode? 2 : 1 ),

-1, 0, null, null, 0, null, null);

// Create the input parameter list from the metadata object

JCO.ParameterList input = JCO.createParameterList(input_md);

// Set the first (and only) input parameter

input.setValue("This is my first JCo example.", "REQUTEXT");

// Create metadata definition of the output parameter list

JCO.MetaData output_md = new JCO.MetaData("OUTPUT");

// Specify the parameters types of the function will be returned

output_md.addInfo("ECHOTEXT", JCO.TYPE_CHAR, 255, 255 * (is_backend_unicode? 2 : 1 ),

-1, 0, null, null, 0, null, null);

output_md.addInfo("RESPTEXT", JCO.TYPE_CHAR, 255, 255 * (is_backend_unicode? 2 : 1 ),

-1, 0, null, null, 0, null, null);

// Create the output parameter list from the metadata object

JCO.ParameterList output = JCO.createParameterList(output_md);

// Call the function

client.execute("STFC_CONNECTION", input, output);

// Print the result

System.out.println("The function 'STFC_CONNECTION' returned the following parameters:\n" +

"----


");

for (int i = 0; i < output.getFieldCount(); i++) {

System.out.println("Name: " + output.getName(i) + " Value: " + output.getString(i));

}//for

// All done

System.out.println("\n\nCongratulations! It worked.");

}

catch (Exception ex) {

System.out.println("Caught an exception: \n" + ex);

}

finally {

// do not forget to close the client connection

if (client != null) client.disconnect();

}

}

}

Hope this help

Francesco