cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to connect into SAP through JCO

former_member227184
Active Participant
0 Kudos

Hi Experts,

I am getting below error while running the JCO connection program.

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 [no sapjcorfc in java.library.path]. java.library.path [C:\Program Files (x86)\Java\jre7\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre7/bin/client;C:/Program Files (x86)/Java/jre7/bin;C:/Program Files (x86)/Java/jre7/lib/i386;C:\Program Files (x86)\RSA SecurID Token Common;C:\Program Files\RSA SecurID Token Common;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Java\jdk1.7.0_75\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\Java\jdk1.7.0_75\bin;;D:\eclipse;;.]

  at com.sap.mw.jco.JCO.<clinit>(JCO.java:871)

  at Bapi1.<init>(Bapi1.java:20)

  at Bapi1.main(Bapi1.java:201)

Below is the program:

import com.sap.mw.jco.IFunctionTemplate;

import com.sap.mw.jco.JCO;

import com.sap.mw.jco.*;

import com.sap.mw.jco.JCO.Table;

public class Bapi1 extends Object {

  JCO.Client mConnection;

  JCO.Repository mRepository;

  public Bapi1() {

  try {

  // Change the logon information to your own system/user

  mConnection =

  //con = JCO.createClient("800","abaper","erp@786","EN","192.168.1.204","00");

  JCO.createClient("800", // SAP client

  "abaper", // userid

  "erp@786", // password

  "EN", // language

  "192.168.1.204", // application server host name

  "00"); // system number

  mConnection.connect();

  System.out.println("Connection Established");

  mRepository = new JCO.Repository("vamshi", mConnection);

  }

  catch (Exception ex) {

  ex.printStackTrace();

  System.exit(1);

  }

  JCO.Function function = null;

  JCO.Table codes = null;

  try {

  function = this.createFunction("BAPI_COMPANYCODE_GETLIST");

  if (function == null) {

  System.out.println("BAPI_COMPANYCODE_GETLIST" +

  " not found in SAP.");

  System.exit(1);

  }

  mConnection.execute(function);

  JCO.Structure returnStructure =

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

  if (!(returnStructure.getString("TYPE").equals("") ||

  returnStructure.getString("TYPE").equals("S"))) {

  System.out.println(returnStructure.getString("MESSAGE"));

  System.exit(1);

  }

  codes =

  function.getTableParameterList().getTable("COMPANYCODE_LIST");

  for (int i = 0; i < codes.getNumRows(); i++) {

  codes.setRow(i);

  System.out.println(codes.getString("COMP_CODE") + '\t' +

  codes.getString("COMP_NAME"));

  }

  }

  catch (Exception ex) {

  ex.printStackTrace();

  System.exit(1);

  }

  try {

  codes.firstRow();

  for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) {

  function = this.createFunction("BAPI_COMPANYCODE_GETDETAIL");

  if (function == null) {

  System.out.println("BAPI_COMPANYCODE_GETDETAIL" +

  " not found in SAP.");

  System.exit(1);

  }

  function.getImportParameterList().

  setValue(codes.getString("COMP_CODE"), "COMPANYCODEID");

  function.getExportParameterList().

  setActive(false, "COMPANYCODE_ADDRESS");

  mConnection.execute(function);

  JCO.Structure returnStructure =

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

  if (!(returnStructure.getString("TYPE").equals("") ||

  returnStructure.getString("TYPE").equals("S") ||

  returnStructure.getString("TYPE").equals("W"))) {

  System.out.println(returnStructure.getString("MESSAGE"));

  }

  JCO.Structure detail =

  function.getExportParameterList().

  getStructure("COMPANYCODE_DETAIL");

  System.out.println(detail.getString("COMP_CODE") + '\t' +

  detail.getString("COUNTRY") + '\t' +

  detail.getString("CITY"));

  }

  }

  catch (Exception ex) {

  ex.printStackTrace();

  System.exit(1);

  }

  mConnection.disconnect();

  }

  public JCO.Function createFunction(String name) throws Exception {

  try {

  IFunctionTemplate ft =

  mRepository.getFunctionTemplate(name.toUpperCase());

  if (ft == null)

  return null;

  return ft.getFunction();

  }

  catch (Exception ex) {

  throw new Exception("Problem retrieving JCO.Function object.");

  }

  }

  public static void main(String args[]) {

  Bapi1 app = new Bapi1();

  }

}

KIndly advice. Your response will be appriciated.

Regards,

Vamshi

Accepted Solutions (0)

Answers (1)

Answers (1)

HAL9000
Product and Topic Expert
Product and Topic Expert
0 Kudos

package com.sap.mw.jco.* belongs to the old JCo 2.x which is completely out of SAP support since almost 3 years. This version was furthermore only released for JRE 1.3 and 1.4 and was never supported to be used with JRE 1.7 environments.

Instead of seeking for a solution to your exception error message, I recommend to download and use the JCo 3.0 instead, which is fully supported also with JRE 1.7 and 1.8. Please learn the new, modern JCo3 API and don't invest any efforts into the deprecated JCo2 API anymore.

You can download JCo 3.0 from here:

http://service.sap.com/connectors

    -> SAP Java Connector

        -> Tools & Services

            -> Download SAP JCo Release 3.0

By the way, the latest JCo patch level 3.0.14 has just been released a few days ago.

Best regards,

Stefan

PS: You posted your AS ABAP back-end password. After having published this, and if this your real one, I would immediately change it in your ABAP back-end and furthermore remove it from your posting.