cancel
Showing results for 
Search instead for 
Did you mean: 

Access ABAP Table using Java (NWDS/JCO)

Former Member
0 Kudos

All,

I am trying to setup a jco connection from java program through NWDS to ECC abap table.

However I am getting the following error in NWDS:

Exception in thread "main" java.lang.ExceptionInInitializerError: JCO.classInitialize(): Could not load middleware layer 'com.sap.mw.jco.rfc.MiddlewareRFC'

JCO.nativeInit(): Could not initialize dynamic link library sapjcorfc [C:\Program Files\Java\jdk1.6.0_45\bin\sapjcorfc.dll: Access is denied]. java.library.path [C:\Program Files\Java\jdk1.6.0_45\bin;.]

and a parity error on my system:

"Parity blocked an attempt by javaw.exe to run sapjcorfc.dll because the file is not approved.  If you require access to this file, please contact your system administrator.  Scroll down for diagnostic data."

Here is the Java code...per the SAP website:

package com.sap.pi.updateAbapSxmbAdminParams;

import com.sap.mw.jco.*;

public class ReadPiAbapTables {

  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("SXMSCONFVLV");

    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("aaa", "aaa", "aaa", "aa", "aa", "aa");

    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;

  } 

}


Accepted Solutions (0)

Answers (2)

Answers (2)

iaki_vila
Active Contributor
0 Kudos

Hi Vicky,

You need authorization to the S_TABU_DIS object, talk with the ABAP basis team about this to find the more restrictive role.

It's not a good idea to use the RFC_READ_TABLE, for the wide permissions needed. You could think to develop a Z RFC for this.  You can check pros/cons in this document: http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/a83ec690-0201-0010-14ac-bd1d75e24...

Regards.

former_member184720
Active Contributor
0 Kudos

Hi Vicky - Have a look at the below thread if it helps.

Former Member
0 Kudos

Thanks Hareesh. I am looking into this along with my security team.

In the mean while would you know the roles and authorizations the JCO RFC user would need to access the ABAP tables from JAVA program?

Thanks