Help on accessing tables available in SAP through Java

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,
You need JCO(Java Connector)
Check this sample code.
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

Similar Messages

  • Help on accessing table available in SAP R/3 System

    Hi All
    A day before I had posted a question regarding the accessing of tables available in SAP R/3 system. 
    I got the following code as reply.  This code is working fine. 
    But in the below example, the QUERY_TABLE IS BSAUTHORS. 
    In my case, the QUERY_TABLE is VBKD(Sales Document Table). 
    When I replace the table name with VBKD in place of BSAUTHORS, I am getting the following error:
    ERROR  BEGIN----
    com.sap.mw.jco.JCO$AbapException: (126) DATA_BUFFER_EXCEEDED: Selected fields do not fit into structure DATA
         at com.sap.mw.jco.JCO$Function.getException(JCO.java:17978)
         at com.sap.mw.jco.JCO$Client.execute(JCO.java:3143)
         at com.insync.JCO.UpdateSalesOrder.main(UpdateSalesOrder.java:34)
    ERROR END----
    Can anyone please give me a solution for this?
    Thanks in Advace,
    Vijay.
    **********************Code**********************
    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");
    //listParams.setValue("VBKD", "QUERY_TABLE"); // ERROR
      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();

    I am also facing the same issue when using 4-way CPU for processing RFC_READ_TABLE I get following error (Error: DATA_BUFFER_EXCEEDED: Selected fields do not fit into structure DATA) .
    when I set the NO_DATA=X in RFC_READ_TABLE then returned data object is empty , is this expected behavior  ? if yes then how do we extract data without getting this error .Help is greatly appreciated

  • Help on accessing tables of SAP from the Java Application

    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.

    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

  • Help on accessing tables in Java available in SAP system

    Hi All
    A day before I had posted a question regarding the accessing of tables available in SAP R/3 system in my Java code.
    I got the following code as reply. This code is working fine.
    But in the below example, the QUERY_TABLE IS BSAUTHORS.
    In my case, the QUERY_TABLE is VBKD(Sales Document Table).
    When I replace the table name with VBKD in place of BSAUTHORS, I am getting the following error:
    ERROR BEGIN----
    com.sap.mw.jco.JCO$AbapException: (126) DATA_BUFFER_EXCEEDED: Selected fields do not fit into structure DATA
    at com.sap.mw.jco.JCO$Function.getException(JCO.java:17978)
    at com.sap.mw.jco.JCO$Client.execute(JCO.java:3143)
    at com.insync.JCO.UpdateSalesOrder.main(UpdateSalesOrder.java:34)
    ERROR END----
    Can anyone please give me a solution for this?
    Thanks in Advace,
    Vijay.
    **********************Code**********************
    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");
    //listParams.setValue("VBKD", "QUERY_TABLE"); // ERROR
    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();

    Hello,
    VBKD is rearly a large table. I suggest to limit the number by filling the FIELDS Table. Also there can be many entries in VBKD and so you should limit the lines by a Where statement in OPTIONS.
    I think a better way are the BAPIs:
    - BAPI_SALESORDER_GETLIST
    - BAPISDORDER_GETDETAILEDLIST
    to get the details of an Salesorder.
    Regards
    Gregor

  • Flow of tables information between sap and java

    How should i pass the table information from sap to java.
    and how to process the data of a table in the java program. i had seen the examples of JCO. BUT I IS VERY CONFUSING (BCOZ I DON'T KNOW JAVA).
    PLZ IF U DON'T MIND SEND ME CODE SNIPPET TO
    1.GET THE TABLE INTO THE JAVA PROGRAM
    2.PROCESSING THE TABLE INFORMATION IN JAVA PROGRAM
    3.MODIFYING THE TABLE INFORMATION IN JAVA PROGRAM
    4.SENDING BACK THE TABLE TO SAP FROM JAVA PROGRAM

    hi,Kondani
    as JCO offers both Client side and server Side programming.
    you can use JCO to connect SAP ABAP.outbound and inbound.
    1) JCO example 5 is about Server side programming java code. And you can see the data mapping is this example.And you must use sm59 to define the connections in SAP before you start.
    2) example 1 is about client side programming.
    try example 1 first. you can get a table from SAP using BAPI.
    Lots of JCO weblog you can see here
    https://www.sdn.sap.com/sdn/search.sdn?contenttype=url&query=jco&selected=9&content=/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fSDN!2fiViews!2fWCM!2fcom.sap.sdn..wcm.search.search_adv%3Fprttheme%3DCSIN%26QueryString=jco%26SearchPluginName=sdn_weblog%26SelectedCustomProps=resourcetype(value=sdn_weblog)
    Regards

  • Flow of tables informaion between sap and java

    How should i pass the table information from sap to java.
    and how to process the data of a table in the java program. i had seen the examples of JCO. BUT I IS VERY CONFUSING (BCOZ I DON'T KNOW JAVA).
    PLZ IF U DON'T MIND SEND ME CODE SNIPPET TO
    1.GET THE TABLE INTO THE JAVA PROGRAM
    2.PROCESSING THE TABLE INFORMATION IN JAVA PROGRAM
    3.MODIFYING THE TABLE INFORMATION IN JAVA PROGRAM
    4.SENDING BACK THE TABLE TO SAP FROM JAVA PROGRAM

    hi,Kondani
    as JCO offers both Client side and server Side programming.
    you can use JCO to connect SAP ABAP.outbound and inbound.
    1) JCO example 5 is about Server side programming java code. And you can see the data mapping is this example.And you must use sm59 to define the connections in SAP before you start.
    2) example 1 is about client side programming.
    try example 1 first. you can get a table from SAP using BAPI.
    Lots of JCO weblog you can see here
    https://www.sdn.sap.com/sdn/search.sdn?contenttype=url&query=jco&selected=9&content=/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fSDN!2fiViews!2fWCM!2fcom.sap.sdn..wcm.search.search_adv%3Fprttheme%3DCSIN%26QueryString=jco%26SearchPluginName=sdn_weblog%26SelectedCustomProps=resourcetype(value=sdn_weblog)
    Regards

  • Accessing events for a Resource through Java API

    I need to display the calendar events for a Resource through a portlet preferably using Java WebServices API. I am trying to figure out if there is a way to authenticate as a Resource, similar to user authentication so that I can display events associated with that resource.
    Thanks,
    Niraj Dhondi

    login as sysop (connectAsSysop) and switch identity to the desired resource (setIdentity) .
    you may need to add the line
    allowsysoplogon_capi = TRUE
    to the [ENG] section in unison.ini .
    g.

  • Accessing tables in other than default schema.

    Hi Experts,
    I am using an Enterprise Bean (Stateless) that uses Common JDBC
    to connect to the Java Schema of the WAS. I have created a
    DataSource alias (created on Default Datasource) and using it for connection.
    My requirement is to <b>get a list of all tables created in the Default schema</b>.
    But when I use DatabaseMetadta.getTables() method, for this type of connection
    it throws out the following exception:
    <b>java.lang.UnsupportedOperationException: Method getTables() not supported by Common JDBC</b>
    I have even tried using the query "Select * from USER_TABLES", but with this one,
    an SQL Exception is thrown saying:
    <b>com.sap.sql.log.OpenSQLException: The SQL statement "SELECT "TABLE_NAME" FROM "USER_TABLES"" contains
    the semantics error[s]: table "USER_TABLES" unknown</b>
    Please tell my how can I use tables in other than the default schema.
    Regards,
    Alka.

    Hi Alka,
    from your post, it is not entirely clear to me what you are atempting to do.
    1) Do you need help with accessing tables in a non-default schema?
    2) Do you want to determine all tables in the default schema?
    If 1), please follow the hints given by Vladimir Pavlov.
    If 2), currently, the method DatabaseMetaData.getTables() is unfortunately not supported in Open SQL/JDBC. We are currently preparing a new download of the NetWeaver Java EE 5 edition. In this version, the getTables() method will be supported.
    Or do you just want to check for the existence of a specific database table in the default schema?
    I hope this helps,
    Best regards,
    Adrian

  • Need Standard BAPI To Create Opportunity in SAP Using Java Connector.

    Hi All,
         What is the standard BAPI to create an opportunity in SAP CRM through Java Connector.
    Please share code if available for doing same. I have found BAPI_OPPORTUNITY_CREATE_MULTI .
    How to create opportunity in SAP through java connector using BAPI_OPPORTUNITY_CREATE_MULTI .

    Hi,
    I think you can search for it or you can create a thread at ABAP section.

  • I am trying to have access tables of the Sql Server through the Oracle

    I am trying to have access tables of the Sql Server through the Oracle and this being occurred the error:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message: [Generic Connectivity using ODBC][H006] The init parameter <HS_FDS_CONNECT_INFO> is not set.
    Please set it in init <orasid>.ora file.
    ORA-02063: preceding 2 lines from HSMSQL
    I created the ODBC with name HSMSQL.
    I made all the configurations in the archives
    tnsnames.ora:
    HSMSQL=
    (DESCRIPTION=
    (ADDRESS= (PROTOCOL = tcp)(HOST = wsus)(PORT = 1521))
    (CONNECT_DATA =
    (SID = HSMSQL)
    (HS = OK)
    listener.ora:
    (SID_DESC = (SID_NAME=HSMSQL)
    (ORACLE_HOME= C:\oracle\ora92)
    (PROGRAM =hsodbc)
    initHS_SID.ora:
    HS_FDS_CONNECT_INFO = HSMSQL
    HS_FDS_TRACE_LEVEL = OFF
    -- Create database link
    create database link HSMSQL.US.ORACLE.COM
    connect to TESTE identified by TESTE2
    using 'HSMSQL';
    But when I execute query the error occurs:
    Select * from TabTeste@HSMSQL
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message: [Generic Connectivity using ODBC][H006] The init parameter <HS_FDS_CONNECT_INFO> is not set.
    Please set it in init <orasid>.ora file.
    ORA-02063: preceding 2 lines from HSMSQL
    Please they help me, thanks, Paulo.

    Hi,
    It seems that your configuration is Ok. By the way, the workaround for this error is:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    [Transparent gateway for ODBC][H001] The environment variable <HS_FDS_CONNECT_INFO> is not set.
    * Set HS_FDS_CONNECT_INFO in the hs{sid}init.ora file to the data source name.
    Example: HS_FDS_CONNECT_INFO = <ODBC DataSource Name>
    * Make sure the hs{sid}init.ora file exists in the ORACLE_HOME/hs/admin directory and has the same name as the SID in the LISTENER.ORA.
    Example: If SID=hsodbc in the listener.ora file, then the hs{sid}init.ora file would be named ORACLE_HOME/hs/admin/inithsodbc.ora
    For more information see if this [url http://forums.oracle.com/forums/thread.jspa?forumID=61&threadID=576975]thread can help you.
    Cheers

  • Is there any table or report that available in SAP for any PR/STR

    HI All,
    Is there any table or report that available in SAP for any PR/STR that are remain opened after S/O canceled.
    Please advice at the earliest.
    Thanks
    Chandru

    Chandru,
    Of course.  The standard MD06 transaction will display ALL MRP generated exception messages, and will take you to the individual material to allow you to determine how you wish to respond to it.
    So, MD06>enter the plant.  Optionally, enter the controller if you wish to limit the results by planner.
    If you are interested in Sales order cancellations, then these exceptions would be categorized by SAP as belonging to the  "exceptions during Scheduling" or "exceptions during availability" groups.  On the Exceptions group tab, select these two items (6&7), deselect the rest. Enter.
    You are now presented with a list of all materials that contain one or more of these exceptions.  From the menu bar at the top, select Edit>Find.  If you get a 'statistics' popup, click through.  Select the 'Find Exceptions' tab.
    Message 26 "excess stock in individual segment" means that in a MTO environment, you have more supply than demand against given order/items (as you would have if a cust. cancelled his MTO order).  Select this message.
    Message 20 "Cancel Process" means that you have a supply element that has NO requirements (as you would have if a cust. cancelled his MTS order).  Select this messaege.
    Message 15 " Postpone process" means that you have supply elements that are scheduled to be received earlier that necessary (as you might have if a Cust cancelled his MTS order). Optionally select this message.
    Clik the green check.  You will now notice that certain rows on the listing are highlighted.  These are the ones that contain your problem children.  Hit the "glasses selected MRP list" button.
    This takes you to the first MD05 of the highlighted items.  Review the problem.  Decide what to do:  Cancel a supply element?  Push out a supply element? Leave it alone?  Call customer service to discuss which order was cancelled and why?  etc etc etc...
    Once you are done with the first material, clik on the 'next material' icon or hit Ctrl-F2.  Repeat.  Continue till all materials have been evaluated and resolved.
    This works for any other MRP message as well.
    Regards,
    DB49

  • Built in Function to Populate an access table from an Oracle Table through VB 6.0

    Dear all,
    Is there any built in function in VB 6.0 to populate an access table directly from an oracle table or SQL Server(Assume Both has the same columns & data type).
    (Just like the DoCmd command which can be used to populate an excel sheet directly from an access table).
    Please help.
    Regards
    Sibby.

    Sibby,
    There is no "built-in" code in VB that I am aware of. However, you could use this code which I wrote for SQL Server. For Oracle, you would have to change to the appropriate table to get all the table names. You can filter by table name to get just your tables like I did below (My_).
    '* Now select all the files and add to access.
    sSQL = "SELECT name, id FROM sysobjects WHERE xtype = 'U' AND SUBSTRING(name, 1, 3) = 'My_' ORDER BY name"
    Set rstTemp = OpenRdSetView(sSQL:=sSQL, adoConnection:=adoConnection)
    On Error GoTo TableExistError
    '* Loop through all my database tables and copy to the Access database.
    With rstTemp
    Do While Not .EOF
    '* Copy this to the Access backup database.
    sTableName = .Fields("Name").Value
    '* Select all records from the SQL Server table and copy to the local Access database.
    sSQL = "SELECT * INTO " & sTableName & " FROM "
    sSQL = sSQL & "[odbc;dsn=" & sDSN & ";UID=" & sUID & ";pwd=" & spwd & ";]." & sTableName
    adoBackupConnection.Execute sSQL, , adExecuteNoRecords
    '* Go to next table.
    .MoveNext
    Loop
    End With

  • Update Yes/No field in access table through oracle procedure

    Hi,
    How to update Yes/No field in access table through oracle procedure. all other fields like AutoNumber, Text I can update it. Yes/No field how to update? Please, any one can help me?
    Thanks and Regards,
    Sudha.

    Sudha Teki wrote:
    select "fldPost" from tblPHd@ODBCLNKNot quite sure what you mean, but the way you select the column would indicate a case sensitive column name
    Look at this example
    SQL> create table t
      2  ("this" varchar2(10))
      3  /
    Table created.
    SQL> insert into t values ('hello')
      2  /
    1 row created.
    SQL> select *
      2    from t
      3  /
    this
    hello
    SQL> select this
      2    from t
      3  /
    select this
    ERROR at line 1:
    ORA-00904: "THIS": invalid identifier
    SQL> select "this"
      2    from t
      3  /
    this
    helloIs your column name also case sensitive?

  • FixedColumncount in sap.ui.table.table is not available in sap.m.table

    Hi,
            i have a requirement of enabling fixedcolumn count in sap.m.table which is available in the sap.ui.table.table
    is there any way to make it available in the sap.m.table...if so please share this will be reallly helpful for me
    thanks in advance
    Regards
    Raghu M

    Hi Santhosh,
                   Thanks for the quick response.
                   I understand what you said.But in my case the table has to render on desktop,tablet and phone bcaz of that only i chose sap.m.table
                   And using sap.m.table is also my requirement.so if you have any way of doing that plz do share
    thanks
    Regards
    Raghu M

  • How Microsoft access could possibly an SAP CRM table

    ould anyone know if it is possible for a Microsoft access system to read an SAP table. If so, how? I have to implement an interface btw MS Access and SAP CRM and I am trying to see how to get it to work.

    Dear Abdul!
    There are probably many ways to achieve what you´re looking for. It heavily depends on several factors, which solution turns out to be the best for you. You should take into account security, data integrity and sensitivty, business context and system architecture, among others.
    First of all though, you should specify wheter you want to access the SAP table for unidirectional read access only, or if you have the requirement to also update data in any SAP table (are you talking about a SAP standard table or a customer Z-table?)
    If you´re looking for a straight forward solution for read-only access, you can create a custom Z* RFC-enabled function module that reads out your SAP table and returns the values to your calling application. You could also use the WebServices interfaces of your SAP WebApplicationServer, depending on your release level. Furthermore, kindly check, if there are standard BAPI´s available that contain the data you need in their return parameters.
    Of course, you also could directly interface on a DBMS level between MS access and your underlying SAP DB, but most likely such a solution will never be supported in any productive environment, and for good reason. So you should look into one of the other options mentioned.
    I´ll gladly provide more detail about any of the mentioned approaches, but would like to have a little more input about your requirements before, so the optimal solutions can be found.
    Kind regards
    Christoph

Maybe you are looking for