JCO CONNECTION.
First of all, let me explain what is a JCO connection?
The JCO Connection or the SAP Java Connector is a middleware component that allows a JAVA application to call or communicate to any SAP systems and vice versa..
There are 2 types of calls that can be made to the SAP Server by the Sap JCO, They are
1)Inbound calls (Java calls ABAP)
2)Outbound calls (ABAP calls Java).
By using a JCO connection, one can call an RFC from the R/3.
It contains 2 .dll files. These are the 2 .dll files that help in calling an RFC.
A JCO connection to an R/3 system is represented by the JCO.Client Class. This class abstracts all functionalities that surround a connection.
First of all you need to import the JCO libraries into your class(es):
import com.sap.mw.jco.*;
The JCO class offers a static method that enables you to create a JCO.Client object
JCO.Client mConnection = CO.createClient("001", // SAP client
"", // userid
"****", // password
"EN", // language (null for the default language)
"", // application server host name
"XX"); // system number
Note: The userid, password etc can be hardcoded or you can create a .properties file and use that particular file. Although its always recommended not to hardcode values.
After the client instance has been created, the connect() method has to be called and then only a connection will be established.
mConnection.connect(); //THe Function modules can be called here }
mConnection.disconnect(); //After the Function module has been executed, the connection has to be closed
JCO.Repository
The JCO.Repository's purpose is to store all meta data of function modules.
This is how a JCO.Repository is created.
JCO.Repository mRepository = new JCO.Repository("JCO Tutorial", mConnection);
Once this is created, do not think that it already contains the meta data. To read any meta data, the method getFunctionTemplate("Name of RMF") has to be called. This can be called as given below.
IFunctionTemplate functionTemplate =mRepository.getFunctionTemplate("Name of RMF");
What does the method getFunctionTemplate() do?
The method getFunctionTemplate() returns an instance of IFunctionTemplate that contains all meta data of a remote function module. You can use this object to create an instance of a JCO.Function.
So now the connection has been done and the RFM has been called.
The next step is, how to get the RFM's table or the export data or if you are importing any data.
This can be achieved by the using the following functions as given below:
1)getExportParameterList() for getting the export parameters
2) getTableParameterList() for getting the table parameters
3)getImportParameterList() for getting the import parameters
You will use the above functions as per your requirement.
1) getTableParameterList()
JCO.Table ztable = function.getTableParameterList().getTable("MY_TABLE");
ztable.appendRow();
ztable.setValue("val1", "VALUE1");
ztable.setValue("val2", "VALUE2");
2)getExportParameterList()
String temp = new String();
temp = function.getExportParameterList().getString( "variable holding exported value" );
3)*getImportParameterList()*String myImportValue = "someValue";
function.getImportParameterList().
setValue(importedvalue, "IMPORTED_VALUE");