Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

JDBC From SAP

Former Member
0 Likes
1,573

Hi All,

Is it possible to access an ORACLE table and fetch data from using JDBC (Java DataBase Connectivity). If it is, could anyone tell me what command/function module etc to use in ABAP (sample code will be highly appreciated).

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,499

Hi,

You can try with EXEC and ENDEXEC to fetch the data using Native SQL.

DATA: BEGIN OF WA, 
        CLIENT(3), ARG1(3), ARG2(3), 
      END OF WA. 
DATA  F3(3). 
F3 = ' 1 '. 
EXEC SQL. 
  SELECT CLIENT, ARG1 INTO :WA FROM AVERI_CLNT 
         WHERE ARG2 = :F3 
ENDEXEC. 
WRITE: / WA-CLIENT, WA-ARG1.

Regards

vijay

Thanks Jesus. I will try and let you know how it goes.

12 REPLIES 12
Read only

Former Member
0 Likes
1,500

Hi,

You can try with EXEC and ENDEXEC to fetch the data using Native SQL.

DATA: BEGIN OF WA, 
        CLIENT(3), ARG1(3), ARG2(3), 
      END OF WA. 
DATA  F3(3). 
F3 = ' 1 '. 
EXEC SQL. 
  SELECT CLIENT, ARG1 INTO :WA FROM AVERI_CLNT 
         WHERE ARG2 = :F3 
ENDEXEC. 
WRITE: / WA-CLIENT, WA-ARG1.

Regards

vijay

Read only

0 Likes
1,499

hi Sandip,

Use Commands <b>EXEC</b> and <b>ENDEXEC</b>

Check this out

http://www.sapdevelopment.co.uk/java/jco/bapi_jco.pdf

Hope it helps,

Regards,

Santosh

Read only

0 Likes
1,499

Thanks for both of your answers. But actually the question I asked is how to establish the connection (the table is sitting outside SAP). My understaning is to access the table, we have to establish a connection (probably JDBC) between SAP and the table. Otherwise how will the native SQL EXEC-ENDEXEC work for that table?

Read only

0 Likes
1,499

Any suggestions on how to set up the database connection?

Read only

0 Likes
1,499

Any suggestions?

Read only

Former Member
0 Likes
1,499

Hi,

I would start looking at the SAP JCo connector for this.

With this, you can design/develop a interface program.

You can check the SAP services, for more details on this connector.

Regards,

Sumant.

Read only

0 Likes
1,499

Thanks Sumant. Can you suggest me where should I start looking at for SAP Services?

Read only

0 Likes
1,499

Hi Sandip. To connect to a secondary database, you use the EXEC SQL command. You first must configure a database connection on DBCO transaction. There you specify the ODBC for the connection, you could use Oracle, MSSQL, DB2, etc; you also specify the server name, user and password... Then, on your program you use:

EXEC SQL

CONNECT dbcon

ENDEXEC

EXEC SQL

OPEN CURSOR dbcur FOR

SELECT * FROM table

ENDEXEC

EXEC SQL

DISCONNECT dbcon

ENDEXEC

That's a very simple example. Check out the help on these sentence.

Hope it Helps.

Jesus

Read only

0 Likes
1,499

Jesus,

Thanks a lot. Let me try this tomorrow. I might come back with some more questions.

One for the moment. While configuring the database connection in DBCO, what does the entry in the field 'Conn. info' look like?

Read only

0 Likes
1,499

Hi Sandip. I've use DBCO to connect to an MSSQL Server DB, however in Conn.info you should put the values to connect to the oracle database. You may wanna check the note 339092:

Connection name: logical name of the connection

DBMS: ORA

User name: Oracle users

DB password: password for the above-mentioned

Oracle user

Conn.info: TNS alias

Permanent: Usually should not be set for a secondary connection.

Hope it Helps.

Jesus

Read only

0 Likes
1,499

Thanks Jesus. I will try and let you know how it goes.

Read only

Former Member
0 Likes
1,499

Hi Sandip,

Here are some links related to SAP JCo:

<a href="http://www.sapgenie.com/faq/jco.htm">http://www.sapgenie.com/faq/jco.htm</a>

<a href="http://help.sap.com/saphelp_nw04/helpdata/en/6f/1bd5c6a85b11d6b28500508b5d5211/content.htm">http://help.sap.com/saphelp_nw04/helpdata/en/6f/1bd5c6a85b11d6b28500508b5d5211/content.htm</a>

Hope this helps.

Regards,

Sumant.