Hi Dear Viewers,
import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;
Bravo, you have done an excellent job.
Knowledge grows by sharing... as I shared my learning with you, please share your learning with others... so that, others can benefit from free knowledge :)
If you have landed on my blog, reading this page - probably you might have tasted the bitterness in connecting/integrating SAP with Java. My past experience also gave me this sourness while I was trying to connect SAP with my Java platform. So, this blog is just to share my learning during the entire process of successful connection with SAP using Java connector (JCo).
Let's get in to details now....
Before you start with your coding, ensure you setup the environment for SAPJCo without which your coding will not be recognised by the environment. Let's talk about Windows environment here.
Environment Setup
- Download the SAPJCo library files from SAP market place.
- Make sure, you find sapjcorfc.dll and librfc32.dll files in the downloaded version.
- Copy sapjcorfc.dll and librfc32.dll to the System32 folder i.e., C:\Windows\System32.
- Also, cross check whether your C:\Windows\System32 has the files MSCVR71.dll and MSCVP71.dll. If not, copy and put it there.
- Now, copy sapjco.jar and sapjcorfc.dll in to the ext folder of your JRE i.e., ...\Java\jrex\lib\ext folder (x in jrex is your Java version - 6 or 7...).
- Now, the last step is to add sapjco.jar to the buildpath of your project folder.
Cool... you are ready with your environment setup. Now, let's take a look how to connect to the SAP repository with Java code.
Connect to SAP with Java class
- IFunctionTemplate, IRepository and JCO are very important classes for connecting to SAP environment.
import com.sap.mw.jco.IFunctionTemplate;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;
- Now, add a connection pool to the intended SAP system. You need to use the method JCO.addClientPool(....) with the SID, max no. of connections, sap client id, credentials to the system i.e., user name/password, language, host and system number. Get the required information from your operating team and pass them to this method addClientPool(....) as arguments.
- Next step is a create a repository using the SID (from above point) i.e., JCO.createRepository("xxxx", SID) and assign it to the repository object i.e., IRepository repo = JCO.createRepository("xxxx", SID).
- Add some logger messages so that you know what's going on in between the processing.
- Make sure you handle all the JCO exceptions (eg., class JCO.Exception) during the process.
- Make an important note that whatever connection pool you are creating should be released once the intended functionality with the code is done after connecting, otherwise your system will go for a toss. You can cleanup/destroy the connection pool by using removeClientPool(..) method - passing your SID as argument i.e., JCO.removeClientPool(SID);
Bravo, you have done an excellent job.
Knowledge grows by sharing... as I shared my learning with you, please share your learning with others... so that, others can benefit from free knowledge :)
Regards,
Keep going...
ReplyDeleteThank u so much :-)
ReplyDeleteIt helped me alot...
plz share more of such learnings once again thank u so much....