Quantcast
Channel: SCN : All Content - Process Integration (PI) & SOA Middleware
Viewing all articles
Browse latest Browse all 7030

Access ABAP Table using Java (NWDS/JCO)

$
0
0

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;

  } 

}

 

 



Viewing all articles
Browse latest Browse all 7030

Trending Articles