Accessing RFCs and BAPIs from enterprise java beans
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
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
Similar Messages
-
Accessing XMLType and CLOB from Enterprise Java Beans
When trying to create a temporary CLOB within the application server the following exception
occurs (connection from Jndi):
Oracle9iAS (9.0.2.0.0) Containers for J2EE initialized
AccessEJBBean.meld: ex=java.lang.NullPointerException java.lang.NullPointerException
at oracle.sql.LobPlsqlUtil.plsql_createTemporaryLob(LobPlsqlUtil.java:1352)
at oracle.jdbc.dbaccess.DBAccess.createTemporaryLob(DBAccess.java:997)
at oracle.sql.LobDBAccessImpl.createTemporaryClob(LobDBAccessImpl.java:240)
at oracle.sql.CLOB.createTemporary(CLOB.java:527)
at com.access.impl.AccessEJBBean.meld(AccessEJBBean.java:67)
(email: [email protected] )When trying to create a temporary CLOB within the application server the following exception
occurs (connection from Jndi):
Oracle9iAS (9.0.2.0.0) Containers for J2EE initialized
AccessEJBBean.meld: ex=java.lang.NullPointerException java.lang.NullPointerException
at oracle.sql.LobPlsqlUtil.plsql_createTemporaryLob(LobPlsqlUtil.java:1352)
at oracle.jdbc.dbaccess.DBAccess.createTemporaryLob(DBAccess.java:997)
at oracle.sql.LobDBAccessImpl.createTemporaryClob(LobDBAccessImpl.java:240)
at oracle.sql.CLOB.createTemporary(CLOB.java:527)
at com.access.impl.AccessEJBBean.meld(AccessEJBBean.java:67)
(email: [email protected] ) -
The differents between Java Beans and Enterprise Java Beans
Please help me!
What is the differents between JavaBeans and Enterprise Java Beans (EJB) ?
Thank's for your answerEnterprise Java Beans are special type of java beans.
EJBs invented to be used via remote VMs or remote computer
systems.They must be deployed on server to become accesible for remote
clients. -
Unable to differentiate between RFC and BAPI
Hi guys,
Nowadays I am studying the above concepts:BAPI and RFC. But I am confused by the two.
So far I learnt that the two are both techniques used to realize communication between SAP and external
systems,and frequently via Remote-enabled Function.
My confusion is the distinctions between the two. Would you please do me a favor? TksHi Alex,
Just check it out these answers.
Remote Function Call :
RFC is an SAP interface protocol. Based on CPI-C, it considerably simplifies the programming of communication processes between systems.
RFCs enable you to call and execute predefined functions in a remote system - or even in the same system.
RFCs manage the communication process, parameter transfer and error handling.
http://help.sap.com/saphelp_47x200/helpdata/en/22/042860488911d189490000e829fbbd/frameset.htm.
BAPI
BAPI stands for Business API(Application Program Interface).
A BAPI is remotely enabled function module
ie it can be invoked from remote programs like standalone JAVA programs, web interface etc..
You can make your function module remotely enabled in attributes of Function module but
A BAPI are standard SAP function modules provided by SAP for remote access.
Also they are part of Businees Objest Repository(BOR).
BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects.
You create business objects and those are then registered in your BOR (Business Object Repository)
which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA.
In this case u only specify the business object and its method from external system
in BAPI there is no direct system call. while RFC are direct system call.
Some BAPIs provide basic functions and can be used for most SAP business object types.
These BAPIs should be implemented the same for all business object types.
Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs.
Whenever possible, a standardized BAPI must be used in preference to an individual BAPI.
another points,
BAPI is object oriented. It is placed under Business objects as methods.
RFC is just a Function module or a call.
RFC: is just a FM that can be called from remote system too(destination defined in transaction SM59).
BAPI: Business Application Programming Interface
A BAPI is a method of a business object defined in the Business Object Repository (BOR). For example, in the BOR, you can find a business object called SalesOrder, which conceptually represents a sales order in the system. A business object typically has several methods that can be used to read, create, modify a particular instance of the business object, or list instances of the business object matching certain selection criteria. These methods are BAPIs.
Technically, a BAPI is implemented using a RFM. But, unlike the non-BAPI RFMs, a BAPI is usually well documented, has nicer parameter names, and is supported by SAP for several SAP software releases. You can browse Business objects and BAPIs in the SAP system using transaction BAPI.
Thanks
Eshwar
*Rewards if useful* -
Hi Eperts,
Would you please tell me the difference between the two,because I learnt that BAPI is a kind of RFC,I'm not sure whether it is right or not.Hi,
RFC Vs BAPI
BAPI are RFC enabled function modules. the difference between RFc and BAPI are business objects. You create business objects and those are then registered in your BOR (Business Object Repository) which can be accessed outside the SAP system by using some other applications (Non-SAP) such as VB or JAVA.
In this case you only specify the business object and its method from external system in BAPI there is no direct system call. while RFC are direct system call Some BAPIs provide basic functions and can be used for most SAP business object types. These BAPIs should be implemented the same for all business object types. Standardized BAPIs are easier to use and prevent users having to deal with a number of different BAPIs. Whenever possible, a standardized BAPI must be used in preference to an individual BAPI. It is not possible to connect SAP to Non-SAP systems to retrieve data using RFC alone. RFC can acces the SAP from outside only through BAPI and same is for vice versa access.
RFC is the protocol used by SAP for remote communication, that is, for communications between remote (independent) systems. RFC is used for communications between two independent SAP systems, or for communications between an SAP system and a non-SAP system, such as an external application. It can also be used for communications between modules on the same system. Using the RFC interfaces you can extend the functionality of R/3 applications from an external program.
Reward if it useful...
Lakshmi. -
Hello Masters,
What Makes the exact difference between RFC and BAPIs. Both can perfom same thing. BAPI uses the RFCs only. Then how can it justify?
Thank youRFC:
RFC --- > Function module and general will be used to make call to function
sending the function (XI has RFC adapter)
BAPI:
BAPI ---> Other version of RFC (Objected oriented) mostly we will use for Sync
calls (Mostly in XI using proxies we will call BAPI's)
Refer these links for more details:
http://sapabap.iespana.es/sapabap/sap/faq/ale_idocs_bapi.htm
http://www.sap-img.com/fu033.htm
BAPI Vs IDOC - in detail
http://searchsap.techtarget.com/tip/1,289483,sid21_gci824860,00.html
/thread/127699 [original link is broken]
IDOC,RFC,BAPI
Re: When and Why we use BAPI, RFC and IDOC.. in XI
Diff... between ALE, IDOC, RFC, BAPI, BADI --- Not clear and clarify
idoc and bapi
Difference among IDOCS,BAPI,RFC?
http://searchsap.techtarget.com/ateQuestionNResponse/0,289625,sid21_cid558752_tax293481,00.html
Differences Between RFC & BAPIS
RFC Vs BAPI
For more details:
refer this thread.
What are idocs, BAPI, RFC?
BAPI is nothing but the Business process programing interface which are standard and stable and these are store in the business object repository.
Standardized programming interface that enables external applications to access business processes and data in an SAP System
RFC is the remote function call which is used to call the function remotely which may be in same system or ather system
its also used communication between SAP systems , between SAP systems ,external systems.
idoc and bapi
Difference among IDOCS,BAPI,RFC?
http://searchsap.techtarget.com/ateQuestionNResponse/0,289625,sid21_cid558752_tax293481,00.html
Differences Between RFC & BAPIS
RFC Vs BAPI
http://www.sap-img.com/abap/ale-bapi.htm
RFC means remote function call,
these are the function modules which can help u to access across the sap and from sap to third party front end,
BAPI means Business application programing interface which is the RFC enable function module and uses in OOPS concept.
RFC ,IDoc and BAPI
ALE/ IDOC
http://help.sap.com/saphelp_erp2004/helpdata/en/dc/6b835943d711d1893e0000e8323c4f/content.htm
http://www.sapgenie.com/sapgenie/docs/ale_scenario_development_procedure.doc
http://edocs.bea.com/elink/adapter/r3/userhtm/ale.htm#1008419
http://www.netweaverguru.com/EDI/HTML/IDocBook.htm
http://www.sapgenie.com/sapedi/index.htm
http://www.sappoint.com/abap/ale.pdf
http://www.sappoint.com/abap/ale2.pdf
http://www.sapgenie.com/sapedi/idoc_abap.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/0b/2a60bb507d11d18ee90000e8366fc2/frameset.htm
http://help.sap.com/saphelp_erp2005/helpdata/en/78/217da751ce11d189570000e829fbbd/frameset.htm
http://www.allsaplinks.com/idoc_sample.html
http://www.sappoint.com/abap.html
http://www.sap-img.com/abap/interview-question-on-bapi-rfc-abap-objects-tables.htm
This is a short description of BAPI and RFC
BAPI stands for Business Application Programming Interface. It is a library of functions that are released to the public as an interface into an existing SAP system from an external system.
RFC is the protocol used to call functions in an R/3 system by a caller external to R/3 or to call programs external to R/3 from an R/3 system. -
What is an enterprise java bean
Hi,
What is an enterprise java bean. How is it different from normal java means.
Thanks a lot,
Chamal.Well an EJB is a object components that lives in the server's container's guts, there are 3 kinds of EJB:
* Session Beans: performs bussines operations
* Entity Beans: represents a table from a relational database
* Message Driven Beans: receives and controlls messages.
more information about it can be found at: http://java.sun.com/products/ejb/reference/docs/index.html -
Calling ABAP BAPIs from a JAVA client - Web Services vs. JCo
Hi All,
When calling BAPIs from a JAVA client, what are the pros/cons for making the call employing JCo vs web service technologies. I understand that using SOAP would play better into the SOA theme and that there are nice tools to generate a WSDL document from a BAPI. Aside from the obvious, are there any performance considerations and/or other major pros/cons to each
Thanks,
MarkHi Mark,
Have you got any information on this. If you have any information on this pls forward to me at <b>[email protected]</b> I am also having this confusion. My question is a bit deviating from your point. If we use XI when developing WDJs with WS, will it help in improving performance and maintenance.will it give any advantage if I use XI with BAPIs to connecto backend from WDJ apps. I got this confusion, becasue of a requirement to develop WDJ apps that will be accessed by 50,000 users. Somebody told client that use of XI willimprove performance.
Any help is greatful
Regards
Ravindra
Message was edited by:
Ravindra Babu Tanguturi -
Missing Enterprise Java Beans Node
I downloaded the Studio Creator 30 day trial version.
But In the server navigator pane there is no Enterprise Java Beans node listed.
How can I enable the Enterprise Java Beans Node in Studio Creator? Or is it a limited version?
Please reply asap.
Thanks in advanceHi.
Porduct version information was as follows....
Java Studio Creator(Build 040903).
Does this mean that I need to upgrade my IDE to update 7?
Thanks a lot for the reply. I almost spent half a day trying to enable the Enterprise Java Beans Node using creator options.
And can I deploy an ear file to creator which I have compiled using JDK1.5?
Thanx again.
Look forward to hearsing from u soon,
Kevin -
How to access AM/VO instance from a Java Service class
Hi,
I have a Java service class that is loaded by Java ServiceLoader (http://download.oracle.com/javase/6/docs/api/java/util/ServiceLoader.html) at run time, and I need to access database tables inside that service class. So is there any way that I can access AM/VO instances from that Java class in order to read database table? Thanks.
Regards,
K HeinYou can access an application module with the the two methods below:
YOURAppModule mAM;
public void setUpAM()
throws NamingException
try
String AMDefName = "YOUR_APP_DEF_NAME";
Hashtable env = new Hashtable(2);
env.put(JboContext.INITIAL_CONTEXT_FACTORY, JboContext.JBO_CONTEXT_FACTORY);
env.put(JboContext.DEPLOY_PLATFORM, JboContext.PLATFORM_LOCAL);
ApplicationModule am = null;
InitialContext ic = new InitialContext(env);
ApplicationModuleHome home = (ApplicationModuleHome) ic.lookup(AMDefName);
am = home.create();
// Connect the AM to a database connection
String jndiDB = "jdbc/HRDS";
am.getTransaction().connectToDataSource(null, jndiDB, false);
boolean connected = am.getTransaction().isConnected();
mAM = (YOURAppModule) am;
catch (NamingException nex)
// do some error processing
throw nex;
catch (Exception eee)
// do some error processing
throw eee;
public void tearDownAM()
if (mAM != null)
if (mAM .getTransaction().isConnected())
mAM .getTransaction().disconnect();
mAM .remove();
}You find the YOUR_APP_DEF_NAME in your application module under 'Configurations' -> AppModuleJndiName.
Make sure you tear down each AM you set up. Otherwise you are running out of resources pretty fast.
Timo -
Hi,
I am a java programmer. I have worked with applets,
servlets, jdbc, etc., but I have never worked with EJB's
Is there a good tutorial of it? Does it depend on certain
API's? Where can I find the classes? I would like to learn
and to develop some applications with EJB's. I will appreciate a lot if someone give me the 1,2,3... of EJB's.
Thanks in advanceThere are suspisiously many tutorials and materials on the Web about EJB.
The principals ones are at Sun's J2EE site:
http://java.sun.com/j2ee/tutorial/doc/J2eeTutorialTOC.html
PetStore Demo
http://java.sun.com/j2ee/download.html#blueprints
JGuru Exercises:
http://developer.java.sun.com/developer/onlineTraining/EJBIntro/exercises.html
Also, look at TheServerSide.com
http://theserverside.com/home/index.jsp
Tutorial on Monson-Haefer "Enterprise Java Bean" book:
http://www.techquestion.net/ejbs/cabinbean1.html
Be careful, however, sometimes it is difficult to repeate
what you have in tutorial.
Good luck,
Jacob Nikom -
Hi Guys,
Ive built a system which uses 8/9 servlets and connects to a postgres database, reads csv files and a few other things, now Ive been asked to implement this using java enterprise beans, how easy/difficult is this? how would I go about it and whats the advantages of using enterprise java beans?
Thanks
TzafCan anyone help?
Thanks
Tzaf -
Preference between rfc and bapi
Hi
If rfc and bapi are available for the similar task to implement ...........as a XI consultant which one you will suggest ?? If so could you please explain me the reason for the same ??
thanks
kumarHi,
From an XI Implementation perspective,
BAPI's do not have a implict COMMIT associated with them and so , in the receiver RFC adapter you need to provide the COMMIT HANDLING FOR BAPI CALLS. This option was avilable from SP 14.
Prior to that you had to writter a warpper RFC and import it into XI and use this instead of the BAPI.
The RFC's conatin an Implicit commit so no such issue here.
regards
Bhavesh -
Accessing custom Portal service from a java application
We have a custom portal service that connects to BW using xmla. How do you access this portal service from a java application. Not from web dynpro, jsp or servlet but from the java code.
Can we use the INITIAL_CONTEXT_FACTORY to get access to the portal service.
Thank You
D.KNow I tried the following:
I've added the prtapi.jar and the service's jar to the additional-lib folder and added the appropriate entries to library.txt and reference.txt.
Now I can obtain now the PortalRuntime, but this is not initialized.
Has anybody a solution for this problem? Help would be high appreciated!
Regards,
Matthias -
How to call a .jar file from a java bean?
any body knows how to call a .jar file from a java bean?
Crosspost!
http://forum.java.sun.com/thread.jspa?messageID=4349619
Maybe you are looking for
-
Hi Experts - We are getting error during interface execution in ODI 11.1.1.6.4. We are unable to find the root cause. Interface is using customized LKM (LKM SQL to Oracle (SQL*Loader). This LKM is basically connecting to SQLSERVER fetching required r
-
Energy saver keeps coming unlocked... sleep won't work
I've noticed when I arrive in the morning that my Mac Pro is awake. But the Time Machine log shows it had been an entire hour since TM was active. I researched various places (including here) and deleted the preference for com.apple.PowerManagement.
-
Does anyone know why all of my picture text message would keep failing to send?
Does anyone know why all of my picture text messages would keep failing to send?
-
Objective setting and appraisal
Hi Colleagues, Am trying to upload a customer defined performance appraisal template using transaction PHAP_CATALOG_PA but am failing to achieve this. May I kindly have a step-by-step giude or notes to help me achieve this. Regards.
-
How to remove MULTIPLE sidebar items from finder?
I accidentally dragged about 1,000 folders into my finder sidbar. Crap. I'd really like to get rid of them quickly and not have to drag them out one at a time. Any ideas? I tried trashing the com.apple.sidebarlists.plist but it didn't do the trick.