on 10-18-2004 4:17 PM
Hello folks,
my question is concerning comunication between EJBs and RFCs. I want to develop a simple session bean that connects to a R/3 back-end, calls a RFC then returns some data, let's say, an example of this could be a list of employees from BAPI_EMPLOYEE_GETDATA.
Ok, by using a web dynpro and adaptive RFC my works could be very very easy, but I'd like to test this way: session (stateless) EJB -> RFC. Can I:
* use JCO.ClientService with a non-portal SAP WAS?
* use embedded JRA (SAP Library stated "The SAP JRA is an add-on for the SAP JCo. If you use the SAP Web AS, the SAP JRA is installed automatically with the SAP JCo.", but I found nothing so in Connector Container Service ...)
* install and configure JRA by myself?
I'm working on a SAP WAS 6.40 Sneak Preview (Java only), and finding a path for easily integrate SAP WAS developed ejbs and external business system. SAP Library suggest to "obtain the JCo connection through the connection framework": is it related to JRA, JCA and SAP Resource Adapter?
Thank you
Pasquale
Hello
before you can use sap jra you have to deploy it (using the webAs deploy tool).
just have a look at the documentation comming with sap jra on how to do this
(also explains how to configure the connection settings).
then you are able to use any remote enabled function modules/BAPIs from within j2ee apps.
(examples are also included in the jra distribution)
if you don't have a copy of sap jra, you can download it at (i'm not sure if a copy comes with the sneak preview)
http://service.sap.com/connectors
-> java connector -> tools & services
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok Franz,
thank you for the answer, but I'm surprised to understand WAS needs JRA installation for let it connect with a business system. I was expecting some system service, like the JCOClientService, available in SAP EP.
I can use this service within an EJB? If yes, what are the packages to import? I'm not interested in using JRA with some different AS like WebLogic or JBoss, my focus is on SAP WAS (6.40), and how let Java side can interact with ABAP side.
Kind regards
Pasquale
i don't know about a jco client service on sap webAS
the only service available is the jco rfc provider which is used to handle calls from r/3 -> j2ee (maps rfc calls into stateless session beans)
i think sap offers jra because it´s an j2ee standard, as where some special services are only available for webAS
yes you can use jra in an ejb.
for the packages to import take a look at the examples and the sap jra documentation (you might also have a look on sun's web site for a detailed description of the java connector architecture / java resource adapter)
an other way to let java interact with r/3 would be to use the java connector, but i think jra is the better solution because it´s j2ee standard and easier to handle than jco
Franz,
you pointed the exact problem: no examples showing what are the packages to import! I'm looking manually in WAS directories and reading carefully SUN J2EE tutorial, and seems I need to make reference to connector.jar and jta.jar in admin/lib, but no mention about I* classes and interfaces, described in SAP Library.
One BIG tip: J2EE tutorial 1.3 has a full detailed description about CCI (common client interface), useful for understanding JCA and SAP JRA, while in same tutorial version 1.4 this section has been omitted, CCI is only cited.
Pasquale
hello
i´ve written a simple stand alone client to test jra connection to a sap system
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import javax.resource.cci.Connection;
import javax.resource.cci.ConnectionFactory;
import javax.resource.cci.Interaction;
import javax.resource.cci.MappedRecord;
import javax.resource.cci.RecordFactory;
import javax.resource.cci.ResultSet;
import javax.resource.spi.ManagedConnectionFactory;
import com.sap.mw.jco.jra.*;
public class Example
{
public void exampleTest()
{
Properties properties = new Properties();
Connection connection=null;
try
{
properties.load(new FileInputStream ("props.txt"));
}
catch(Exception e)
{
System.out.println("properties could not be loaded");
e.printStackTrace();
}
try
{
ManagedConnectionFactory mf = new JRA.ManagedConnectionFactoryImpl(properties);
ConnectionFactory cf = (ConnectionFactory)mf.createConnectionFactory();
connection = cf.getConnection();
RecordFactory rf = cf.getRecordFactory();
Interaction interaction = connection.createInteraction();
MappedRecord request = rf.createMappedRecord("STFC_STRUCTURE");
//----
-
// Since the STFC_STRUCTURE does not create any new records
// in the data base, you do not need to start a trancation here.
//----
-
// fill out a structure with dummy data
MappedRecord importstruct = (MappedRecord)request.get("IMPORTSTRUCT");
importstruct.put("RFCFLOAT","1.23456");
importstruct.put("RFCCHAR4","ABCD");
importstruct.put("RFCINT1", "11");
importstruct.put("RFCDATE", "2001-08-24");
// fill out a table with dummi data
ResultSet rfctable = (ResultSet)request.get("RFCTABLE");
for (int i = 0; i < 10; i++)
{
rfctable.moveToInsertRow();
rfctable.updateString("RFCCHAR4","EFGH");
rfctable.updateInt("RFCINT1", i);
rfctable.updateString("RFCDATE", "1961-08-24");
rfctable.updateDouble("RFCFLOAT",1.65432);
rfctable.insertRow();
}
// call defined RFC and cast the result to the optional ResultMap interface
ResultMap response = (ResultMap)interaction.execute(null,request);
// release resources
interaction.close();
// create an xml file from the output of the called RFC
// the optional interface ResultMap offers additional methods, like writeXML
FileOutputStream os = new FileOutputStream(response.getRecordName() + "_Structure_from_NotManaged_Example.xml");
response.writeXML(new java.io.OutputStreamWriter(os,"UTF-8"),true);
os.close();
ResultSet resultSet = (ResultSet)response.get("RFCTABLE");
System.out.println("Name of the table is: "+resultSet.getRecordName());
}
catch (Exception ex)
{
ex.printStackTrace();
System.exit(1);
}
finally
{
if (connection != null)
{
try
{
connection.close();
}
catch(Exception exception1)
{}
}
}
}
public static void main(String[] args)
{
Example anExample = new Example();
try
{
anExample.exampleTest();
}
catch(Throwable t)
{
t.printStackTrace();
}
}
}
the property file looks like this:
jco.client.client=010
jco.client.user=user
jco.client.passwd=pass
jco.client.ashost=your host
jco.client.sysnr=00
but this only an example for a standalone test client
to use jra inside j2ee first deploy the connector with the settings you need and then get a connection to it using jndi
i don´t have an example at hand for using it inside an ejb or servlet, but if you need one i'll have a look
Hi,
you might want to try with the Connectivity builder. Docs can be found in the development manual: http://help.sap.com/saphelp_nw04/helpdata/en/fe/a3996fa314f94f8a0c3475b08636d0/frameset.htm
and from there to Connectivity and Interoperability->SAP Enterprise Connector.
Here it's described how to generate a JCo Proxy including an example.
Regards,
Benny
Hi,
I would not recommend to use the Connectivity Builder, because each time our SAP folks are changing their Customisation which does relate to a BAPI which is used over the Connectivity Builder, the JCO Proxy gets out of date and so you have to generate again new JCO Proxy. Now for just testing a bit this is now problem, but in a real life environment you can not expect to recompile all your programs each time our SAP friends change something, therefore we use the metainformation functionality of JCO for marshalling/unmarshalling at runtime the necessary objects for a BAPI call.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.