cancel
Showing results for 
Search instead for 
Did you mean: 

Call JAVA from ABAP?

Former Member
0 Kudos

hello to all!

the blog from gregor wolf is very good and

i successfully brought the local server to run!

how can i merge the code in ejb?

i have few time.

greetings

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello

it is not possible to create a JCO.Server inside an EJB because EJB spec forbids to start threads or open network sockets.

If your inside a J2EE 1.4 or higher J2EE Application Server you could have look at Resource Adapters which are part of the <a href="http://java.sun.com/j2ee/connector/index.jsp">Java Connector Architecture</a>

With an Inbound Resource Adapter you are able to start a JCO.Server and map Calls to an EJB

If your are running a SAP J2EE Application Server you could have a look at the "RFC Engine Service" which allows you to map incoming RFC calls to EJBs

regards franz

reward points if useful

Message was edited by:

Franz Ferner

Former Member
0 Kudos

Hi!

Wow, thats hard...:-)

Are there Tutorials for my Problem?

Im new in this area.

Best greetings

Denis Kühne

ps: which surprises me is that it was described here without jra... is confused

are there other possibilities to call a method from abap to java(not local in java-application)?

e.g. over functional module two numbers export and adds in java method and send back?

sorry for my english

Denis Kühne

Former Member
0 Kudos

Hello

this thread describes the use of the RFC Engine Service, which is only available on SAP J2EE APP Servers (so if your app should run on a SAP J2EE Server your lucky)

regards franz

Former Member
0 Kudos

Yes, I use also the SAP J2EE server.

How I get the connection from the server to bean(methods)?

If I have connection from visual admin to sap ... how I use processFunction()

ask over ask...

thanks in advance

Denis Kühne

ps: can i make a Jco connection in "WEBAS Administrator" in SAP J2EE Engine Start Page? How?

Former Member
0 Kudos

Hello

have a look at this <a href="http://help.sap.com/saphelp_47x200/helpdata/en/6a/82343ecc7f892ee10000000a114084/frameset.htm">link</a>

seems like the service name ist not "RFC Engine Service" but "JCO RFC Provider"

to create an RFC Server use visual admin, <your server> -> server -> services -> JCO RFC Provider or "RFC Engine Service"

create a new RFC Destination and fill in all required parameters - RFC Destination and Respository

save settings and start RFC Destination

then logon to your SAP R/3 System and check if J2EE Engine has registered at your SAP System with the given ProgramID (either call Function Module RFC_PING with given Destination or check in Transaction smgw)

to map a call from R/3 to an EJB create an stateless Session bean which has the business method void processFunction(JCO.Function). Implement also a local home interface

Give the bean the JNDI of the Function Module (for Example STFC_CONNECTION), then the JCO RFC Provider service should map calls to your EJB

regards

franz

reward points if useful

Former Member
0 Kudos

Hi!

Now I understand and the Connection works fine. jep

But I am also java noob. Are there examples (JCO.Function and OTHER) or beans with implements processFunctions? How I must?

To which I need the home local interface? What there do I write?

thanks in advance

Former Member
0 Kudos

i have this code in my bean (not complete):


package com.sap;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import com.sap.mw.jco.*;

/**
 * @ejbHome <{com.sap.RFCHome}>
 * @ejbLocal <{com.sap.RFCLocal}>
 * @ejbLocalHome <{com.sap.RFCLocalHome}>
 * @ejbRemote <{com.sap.RFC}>
 * @stateless 
 * @transactionType Container
 */
public class RFCBean implements SessionBean {

	public void ejbRemove() {
	}

	public void ejbActivate() {
	}

	public void ejbPassivate() {
	}

	public void setSessionContext(SessionContext context) {
		myContext = context;
	}

	private SessionContext myContext;
	/**
	 * Create Method.
	 */
	public void ejbCreate() throws CreateException {
		// TODO : Implement
	}

	/**
	 * Business Method.
	 */
	public void processFunction(JCO.Function function) {
		try {

			JCO.ParameterList input = function.getImportParameterList();
			JCO.ParameterList output = function.getExportParameterList();
			JCO.ParameterList tables = function.getTableParameterList();

			System.out.println("getImportParameterList:" + input);

			if (function.getName().equals("STFC_CONNECTION")) {
				output.setValue(input.getString("REQUTEXT"), "ECHOTEXT");
				output.setValue(
					"This is a response from RFCBean.java",
					"RESPTEXT");
			} else if (function.getName().equals("STFC_STRUCTURE")) {
				JCO.Structure sin = input.getStructure("IMPORTSTRUCT");
				JCO.Structure sout = (JCO.Structure) sin.clone();
				try {
					System.out.println(sin);
				} catch (Exception ex) {
					System.out.println(ex);
				}
				output.setValue(sout, "ECHOSTRUCT");
				output.setValue(
					"This is a response from RFCBean.java",
					"RESPTEXT");
			} //if 

		} catch (java.lang.Exception e) {
			e.printStackTrace();
		}
	}

}

in my local home i have nothing coded.

When I the bean deploy the following error message comes:

<i>stateless session bean must define exactly one create method with no arguments in its local home interface</i>

What is it? I'm Beginner

thanks in advance

Former Member
0 Kudos

Hello

your interfaces should look something like this

Remote Interface:


import ...

public interface RFC extends EJBObject {
   public void processFunction(JCO.Function function)
} 

Home Interface:


import ...

public interface RFCHome extends EJBHome {
  RFC create() throws RemoteException, CreateException;
} 

regards franz

Former Member
0 Kudos

Hi!

the ejb is deployed...

but in sap when i call the function "STFC_CONNECTION" brings the system the error message: "java.lang.illegalargumentexception".

here my testcode in sap:


*&---------------------------------------------------------------------*
*& Report  ZDK_TEST02                                                  *
*&                                                                     *
*&---------------------------------------------------------------------*
*&  Test outbound JCO connection
**
*&                                                                     *
*&---------------------------------------------------------------------*

REPORT  ZDK_TEST02                                                  .

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 'JAVARFC'.

CALL FUNCTION 'STFC_CONNECTION'
  DESTINATION 'JAVARFC'
  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.

i tested the connection to j2ee_engine in sm59, that works fine.

in the ejb i had the jndi-name "STFC_CONNECTION".

what is it.need help...

greeting in advance

Former Member
0 Kudos

first try to remove all your code from the method processFunction, redeploy and test RFC call again, to see if basic functionality works.

Than add code to processFunction again

could you also paste your current java coding

regards

franz

Former Member
0 Kudos

here my current code:

package com.sap;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import com.sap.mw.jco.*;
//import java.util.GregorianCalendar;
//import java.io.FileOutputStream;
/**
 * @ejbHome <{com.sap.RFCHome}>
 * @ejbRemote <{com.sap.RFC}>
 * @stateless 
 * @transactionType Container
 */
public class RFC3Bean implements SessionBean  {

	static public class Repository
		extends JCO.BasicRepository
		implements IRepository {
		public Repository(String name) {
			super(name);
		}
	}

	protected static IRepository repository;

	static {

		repository = new Repository("TestRepository");

		JCO.MetaData fmeta = new JCO.MetaData("STFC_CONNECTION");
		fmeta.addInfo(
			"REQUTEXT",
			JCO.TYPE_CHAR,
			255,
			0,
			0,
			JCO.IMPORT_PARAMETER,
			null);
		fmeta.addInfo(
			"ECHOTEXT",
			JCO.TYPE_CHAR,
			255,
			0,
			0,
			JCO.EXPORT_PARAMETER,
			null);
		fmeta.addInfo(
			"RESPTEXT",
			JCO.TYPE_CHAR,
			255,
			0,
			0,
			JCO.EXPORT_PARAMETER,
			null);
		repository.addFunctionInterfaceToCache(fmeta);

		fmeta = new JCO.MetaData("STFC_STRUCTURE");
		fmeta.addInfo(
			"IMPORTSTRUCT",
			JCO.TYPE_STRUCTURE,
			144,
			0,
			0,
			JCO.IMPORT_PARAMETER,
			"RFCTEST");
		fmeta.addInfo(
			"ECHOSTRUCT",
			JCO.TYPE_STRUCTURE,
			144,
			0,
			0,
			JCO.EXPORT_PARAMETER,
			"RFCTEST");
		fmeta.addInfo(
			"RESPTEXT",
			JCO.TYPE_CHAR,
			255,
			0,
			0,
			JCO.EXPORT_PARAMETER,
			null);
		fmeta.addInfo("RFCTABLE", JCO.TYPE_TABLE, 144, 0, 0, 0, "RFCTEST");
		repository.addFunctionInterfaceToCache(fmeta);

		JCO.MetaData smeta = new JCO.MetaData("RFCTEST");
		smeta.addInfo("RFCFLOAT", JCO.TYPE_FLOAT, 8, 0, 0);
		smeta.addInfo("RFCCHAR1", JCO.TYPE_CHAR, 1, 8, 0);
		smeta.addInfo("RFCINT2", JCO.TYPE_INT2, 2, 10, 0);
		smeta.addInfo("RFCINT1", JCO.TYPE_INT1, 1, 12, 0);
		smeta.addInfo("RFCICHAR4", JCO.TYPE_CHAR, 4, 13, 0);
		smeta.addInfo("RFCINT4", JCO.TYPE_INT, 4, 20, 0);
		smeta.addInfo("RFCHEX3", JCO.TYPE_BYTE, 3, 24, 0);
		smeta.addInfo("RFCCHAR2", JCO.TYPE_CHAR, 2, 27, 0);
		smeta.addInfo("RFCTIME", JCO.TYPE_TIME, 6, 29, 0);
		smeta.addInfo("RFRDATE", JCO.TYPE_DATE, 8, 35, 0);
		smeta.addInfo("RFCDATA1", JCO.TYPE_CHAR, 50, 43, 0);
		smeta.addInfo("RFCDATA2", JCO.TYPE_CHAR, 50, 93, 0);
		repository.addStructureDefinitionToCache(smeta);
	}
	
	

	public void ejbRemove() {
	}

	public void ejbActivate() {
	}

	public void ejbPassivate() {
	}

	public void setSessionContext(SessionContext context) {
		myContext = context;
	}

	private SessionContext myContext;
	/**
	 * Create Method.
	 */
	public void ejbCreate() throws CreateException {
		// TODO : Implement
	}

	/**
	 * Business Method.
	 */
	public void processFunction(JCO.Function function) {
		try {

			JCO.ParameterList input = function.getImportParameterList();
			JCO.ParameterList output = function.getExportParameterList();
			JCO.ParameterList tables = function.getTableParameterList();

			System.out.println("getImportParameterList:" + input);

			if (function.getName().equals("STFC_CONNECTION")) {
				output.setValue(input.getString("REQUTEXT"), "ECHOTEXT");
				output.setValue(
					"This is a response from RFCBean.java",
					"RESPTEXT");
			} else if (function.getName().equals("STFC_STRUCTURE")) {
				JCO.Structure sin = input.getStructure("IMPORTSTRUCT");
				JCO.Structure sout = (JCO.Structure) sin.clone();
				try {
					System.out.println(sin);
				} catch (Exception ex) {
					System.out.println(ex);
				}
				output.setValue(sout, "ECHOSTRUCT");
				output.setValue(
					"This is a response from RFCBean.java",
					"RESPTEXT");
			} //if 

		} catch (java.lang.Exception e) {
			e.printStackTrace();
		}
	}

}

Former Member
0 Kudos

HI!

My Problem is solved!

The code from the description:

/**
 * @ejbHome <{com.sap.RFCHome}>
 * @ejbLocal <{com.sap.RFCLocal}>
 * @ejbLocalHome <{com.sap.RFCLocalHome}>
 * @ejbRemote <{com.sap.RFC}>
 * @stateless 
 * @transactionType Container
 */

was wrong.

Thanks for your great help...im so happy....full points for you

Former Member
0 Kudos

Hello

you can also remove this code


static public class Repository
		extends JCO.BasicRepository
		implements IRepository {
		public Repository(String name) {
			super(name);
		}
	}
 
	protected static IRepository repository;
 
	static {
 
		repository = new Repository("TestRepository");
 
		JCO.MetaData fmeta = new JCO.MetaData("STFC_CONNECTION");
		fmeta.addInfo(
			"REQUTEXT",
			JCO.TYPE_CHAR,
			255,
			0,
			0,
			JCO.IMPORT_PARAMETER,
			null);
		fmeta.addInfo(
			"ECHOTEXT",
			JCO.TYPE_CHAR,
			255,
			0,
			0,
			JCO.EXPORT_PARAMETER,
			null);
		fmeta.addInfo(
			"RESPTEXT",
			JCO.TYPE_CHAR,
			255,
			0,
			0,
			JCO.EXPORT_PARAMETER,
			null);
		repository.addFunctionInterfaceToCache(fmeta);
 
		fmeta = new JCO.MetaData("STFC_STRUCTURE");
		fmeta.addInfo(
			"IMPORTSTRUCT",
			JCO.TYPE_STRUCTURE,
			144,
			0,
			0,
			JCO.IMPORT_PARAMETER,
			"RFCTEST");
		fmeta.addInfo(
			"ECHOSTRUCT",
			JCO.TYPE_STRUCTURE,
			144,
			0,
			0,
			JCO.EXPORT_PARAMETER,
			"RFCTEST");
		fmeta.addInfo(
			"RESPTEXT",
			JCO.TYPE_CHAR,
			255,
			0,
			0,
			JCO.EXPORT_PARAMETER,
			null);
		fmeta.addInfo("RFCTABLE", JCO.TYPE_TABLE, 144, 0, 0, 0, "RFCTEST");
		repository.addFunctionInterfaceToCache(fmeta);
 
		JCO.MetaData smeta = new JCO.MetaData("RFCTEST");
		smeta.addInfo("RFCFLOAT", JCO.TYPE_FLOAT, 8, 0, 0);
		smeta.addInfo("RFCCHAR1", JCO.TYPE_CHAR, 1, 8, 0);
		smeta.addInfo("RFCINT2", JCO.TYPE_INT2, 2, 10, 0);
		smeta.addInfo("RFCINT1", JCO.TYPE_INT1, 1, 12, 0);
		smeta.addInfo("RFCICHAR4", JCO.TYPE_CHAR, 4, 13, 0);
		smeta.addInfo("RFCINT4", JCO.TYPE_INT, 4, 20, 0);
		smeta.addInfo("RFCHEX3", JCO.TYPE_BYTE, 3, 24, 0);
		smeta.addInfo("RFCCHAR2", JCO.TYPE_CHAR, 2, 27, 0);
		smeta.addInfo("RFCTIME", JCO.TYPE_TIME, 6, 29, 0);
		smeta.addInfo("RFRDATE", JCO.TYPE_DATE, 8, 35, 0);
		smeta.addInfo("RFCDATA1", JCO.TYPE_CHAR, 50, 43, 0);
		smeta.addInfo("RFCDATA2", JCO.TYPE_CHAR, 50, 93, 0);
		repository.addStructureDefinitionToCache(smeta);
	}

...because the repository is fetched by the JCo RFC Provider, so no need to build it on your own.

regards franz

Answers (2)

Answers (2)

Former Member
0 Kudos

new Question

Hi!

I want two numbers on java hand over, calculate and return.

How does the source code have to look in java?

ps: im java beginner

Former Member
0 Kudos

Hi!

I want two numbers on java hand over, calculate and return.

How does the source code have to look in java?

ps: im java beginner