cancel
Showing results for 
Search instead for 
Did you mean: 

How to access SAP database tables with Java (Jco)

Former Member
0 Kudos

Hi!

I need to develop a Java Client for SAP with access to the SAP database. Is there a way to do this directly in Java (the db access) or do I have to use some ABAP logic in between to get the information to the java client? If so, are there any existing ABAP functions to read AND write db tables? Or do I have to create my own wrappers for each table I need to read and write?

Thanks,

Konrad

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos
Former Member
0 Kudos

Hi!

Thanks so far...

The second link is a pdf about JCO... but I cannot see how to access the SAP db in there. I know how to run BAPIs but I do not know how to access the db. I need something like SQL...

The first link shows more about this stuff but I think this is some different technology than JCO, isn't it? If so, how can I develop a java client using this technology for a SAP R3 system?

Former Member
0 Kudos

btw:

the option buttons to set the points for an answer are gone in my browser! I don't know if this is a problem with the SDN or with my browser but in the moment I cannot give you points for your answer...

Sorry!

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Konrad,

Did you get any solution on accessing SAP database schema from a java client. We too have a similar requirement. Please do let me me know if you have any identified any solution.

Regards

Vinay Rane

Former Member
0 Kudos

Hi!

Unfortunately not :-(. The only possible way I found is to create ABAP functions which provide access to the DB tables. Sorry...

Regards,

Konrad

Former Member
0 Kudos

Hi Konrad,

Usually there is no way round using RFC wrappers.

SAP uses some layer above the database for caching and locking so if you want to avoid inconsistencies better go the official way.

These tables you have to access: I guess they exist for some purpose. Isn't there business functionality that you could simply reuse?

If there is no functionality on top of these tables of course you can simply access the tables directly using e.g. plain JDBC.

Regards

Markus

Former Member
0 Kudos

Hi!

No, there is no logic around this tables...

What do you mean by "access the tables directly with JDBC"? Do you mean directly through the database itself without SAP at all?

Thanks,

Konrad

Former Member
0 Kudos

Well it all depends on the logic behind the tables and the way they interact with the regular SAP application. If the tables do not interact at all but are just supplements and you are writing a maintenance application you just [might] get away with directly accessing them through JDBC.

However in view of where they reside and how the logic interacts with the rest of SAP you would surely be better off writing your own BAPIs to interact with the additional tables in an object coherent manner.

Enjoy

Former Member
0 Kudos

Hi!

Those tables are completely independent to SAP and there is NO interaction to the regular SAP processes. But anyhow, I will access them through self written ABAP interfaces to be on the safe side...

Thanks,

Konrad

Former Member
0 Kudos

hi,

i am sending code .i think it will help u

try {

// Add a connection pool to the specified system

// The pool will be saved in the pool list to be used

// from other threads by JCO.getClient(SID).

// The pool must be explicitely removed by JCO.removeClientPool(SID)

this.objClient = JCO.createClient(strClient, // SAP client

strUserID, // userid

strPwd, // password

strLang, // language

strHost, // host name

strSysNr);

this.objClient.connect();

// Create a new repository

// The repository caches the function and structure definitions

// to be used for all calls to the system SID. The creation of

// redundant instances cause performance and memory waste.

this.objIRepository =

JCO.createRepository("MYRepository", this.objClient);

} catch (JCO.Exception ex) {

System.out.println("Caught an exception: \n" + ex);

}

JCO.Function objFunction =

this

.objIRepository

.getFunctionTemplate("BAPI_MATERIAL_AVAILABILITY")

.getFunction();

objFunction.getImportParameterList().setValue(strPlant, "PLANT");

objFunction.getImportParameterList().setValue(strMaterial, "MATERIAL");

objFunction.getImportParameterList().setValue(strQuantity, "UNIT");

this.objClient.execute(objFunction);

JCO.Structure ret =

objFunction.getExportParameterList().getStructure("RETURN");

String strRetMsg = ret.getString("MESSAGE");

if (strRetMsg.equals("Unit is not created in language")) {

arrResult.add("error");

return arrResult;

} else {

String strQty1 =

objFunction.getExportParameterList().getString("AV_QTY_PLT");

if (strQty1.equals("0"))

result = "no";

else

result = "yes";

arrResult.add(result);

return arrResult;

}

}

/**

Former Member
0 Kudos

Hi!

Can you explain me how this code will solve my problem with accessing db tables from jco???

Thanks anyway,

Konrad

Former Member
0 Kudos

Hi

IF you are referring to DB Tables then JCO is not the right solution , since JCO is used for accessing Function Module /BAPI written in ABAP .

Let me take certain consideration :

1)If you requirement is that you have to access the SAP data directly then through java you can directly access it using JDBC Connectors

2) If you want to use ABAP specific FM which do this processing( fetching data from SAP specific database tables ) then JCO is the right option.

All depends on ur spefic requirement .Can you please be more specific about your requirements ?

hope this solves your confusion, Please do not forget to reward points .

regards

rajesh kr

Former Member
0 Kudos

Hi!

My requirements are:

- the software should run as external java client (should be triggered/started out of SAP)

- it must be able to access database tables of SAP (read and write access)

- it must be able to create SAP objects like documents, material masters

If it is possible, I would like to access the database directly via SQL (all tables involved are customer created tables and not SAP tables) and create the SAP objects using JCo.

Tell me more about this jdbc connector. Is it possible to access tables directly with it also if the tables are in the abap schema or only if they are created in s special java schema?

Thanks,

Konrad

Former Member
0 Kudos
Former Member
0 Kudos

Hi Konard,

I think for that anyway you will have to use JCO as the middleware to connect to SAP R/3.

So what you can to do is to write three RFCs and call them through JCO from your JAVA application.

1. First BAPI for reading the dictionary information about an SAP table.

2. Second to read data from the table.

3. And, third to write data to that table.

But if you want to edit any table (and not a specific table) then your program will become even more complex since then you will have to pass the table name and information dynamically to the BAPIs.

Best regards,

Guru.

Former Member
0 Kudos

Dou you mean 3 RFCs for all tables or for each table. We are talking about 40 tables here. My plan was to create one function for each table and pass the db table as "tables" parameter to the java application. Another import parameter specifies the action in the RFC. Can be either "Insert", "Update", "Read" or "Delete" and within the java code I can modify the table, add, update or delete rows...

I would realy like to use ONE RFC for all tables but I don't know how...

Thanks,

Konrad

Former Member
0 Kudos

Hi Konrad,

I think you would have to create wrappers..

I dont think there SAP database tables are remotely accessible..

Its possible only in case of Internet Prive Configurator(IPC) in SAP-CRMm where the database tables are accessible via java programs..

For JCO, you would have to call BAPI's or remotely enabled function moudules...

Regards,

Tanveer.

Please mark helpful answers..