on 06-26-2006 4:28 PM
Hi All
I want to access some tables available in SAP through my Java program. Do I have to write any code for database connectivity or straightaway I can write SQL statements in my Java code?
Can anyone please suggest the sample code for this?
Thanks in Advance,
Vijay.
HI
GOOD
GO THROUGH THIS LINK
http://www.persistentsys.com/presentation/Java_SAP_Integration.pdf
THANKS
MRUTYUN
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay,
You would have to use JCO(Java Connector).
Using this you would be able to access the remotely enabeled function modules in SAP.
In this function modules, you can write your code of fetching data.
I have some excellent document on this which shall be useful to you.
Let me know your email address and i shall send it to you.
Regards,
Tanveer.
<b>Please mark helpful answers</b>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vijay,
Check this http://sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/ep/portal-content/simpl... queries of sap tables from java
People saying that it is pretty usefull document.
Best regards, Maksim Rashchynski.
the above one is with out connection pool, check this with connection pool.
import com.sap.mw.jco.*;
public class JcoTest {
private static JCO.Client theConnection;
private static IRepository theRepository;
private static final String POOL_NAME = "myPool";
public static void main(String[] args) {
JCO.Pool connPool = JCO.getClientPoolManager().getPool(POOL_NAME);
if (connPool == null) {
JCO.addClientPool(POOL_NAME,
5, //number of connections in the pool
"client",
"username",
"paswword",
"EN",
"hostname",
"00");
}
theConnection = JCO.getClient(POOL_NAME);
retrieveRepository();
try {
JCO.Function function = getFunction("RFC_READ_TABLE");
JCO.ParameterList listParams = function.getImportParameterList();
listParams.setValue("BSAUTHORS", "QUERY_TABLE");
theConnection.execute(function);
JCO.Table tableList = function.getTableParameterList().getTable("DATA");
if (tableList.getNumRows() > 0) {
do {
for (JCO.FieldIterator fI = tableList.fields();
fI.hasMoreElements();)
{
JCO.Field tabField = fI.nextField();
System.out.println(tabField.getName()
+ ":t" +
tabField.getString());
}
System.out.println("n");
}
while (tableList.nextRow() == true);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
JCO.releaseClient(theConnection);
}
private static void retrieveRepository() {
try {
theRepository = new JCO.Repository("saprep", theConnection);
}
catch (Exception ex)
{
System.out.println("failed to retrieve repository");
}
}
public static JCO.Function getFunction(String name) {
try {
return theRepository.getFunctionTemplate(name.toUpperCase()).getFunction();
}
catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}
Regards
vijay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You need JCO(Java Connector)
Check this sample code.you have to call the RFC RFC_READ_TABLE
import com.sap.mw.jco.*;
public class JcoTest {
private static JCO.Client theConnection;
private static IRepository theRepository;
public static void main(String[] args) {
createConnection();
retrieveRepository();
try {
JCO.Function function = getFunction("RFC_READ_TABLE");
JCO.ParameterList listParams = function.getImportParameterList();
listParams.setValue("BSAUTHORS", "QUERY_TABLE");
theConnection.execute(function);
JCO.Table tableList = function.getTableParameterList().getTable("DATA");
if (tableList.getNumRows() > 0) {
do {
for (JCO.FieldIterator fI = tableList.fields();
fI.hasMoreElements();)
{
JCO.Field tabField = fI.nextField();
System.out.println(tabField.getName()
+ ":t" +
tabField.getString());
}
System.out.println("n");
}
while (tableList.nextRow() == true);
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private static void createConnection() {
try {
theConnection = JCO.createClient("000", "DDIC", "minisap", "en", "sincgo", "00");
theConnection.connect();
}
catch (Exception ex) {
System.out.println("Failed to connect to SAP system");
}
}
private static void retrieveRepository() {
try {
theRepository = new JCO.Repository("saprep", theConnection);
}
catch (Exception ex)
{
System.out.println("failed to retrieve repository");
}
}
public static JCO.Function getFunction(String name) {
try {
return theRepository.getFunctionTemplate(name.toUpperCase()).getFunction();
}
catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
}
Regards
vijay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
7 | |
7 | |
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.