JAVA通過JCO串連SAP例子__JAVA

來源:互聯網
上載者:User

1.把librfc32.dll,sapjcorfc.dll 放到伺服器的系統的c:\windows\system32目錄下

   (不然會報錯:sap Field IT_TABLnot a member of TABLES) 2.下載 sap.jar;sapjco.jar;sappool.jar加到JAVA應用下.
3.下面類代碼可以查物料資料
 
import com.sap.mw.jco.*;
import com.sap.mw.jco.JCO.Function;
class SAPServer extends JCO.Server
{
 
    public SAPServer(JCO.Repository repo)
    {
        super ("10.10.10.50", "sapgw00", "ABC", repo);
    }    
}
class SAPLogon
{
 public JCO.Client mConnection;
 public JCO.Repository mRepository;
 public SAPLogon(String client, String userid, String password, String language,
            String ip, String system_number)
 {
  try {
  
         mConnection = JCO.createClient(client, 
                                       userid, 
                                       password, 
                                       language, 
                                       ip, 
                                       system_number);
   mConnection.connect();
   mRepository = new JCO.Repository("Lee", mConnection);
   System.out.println("SAP串連成功");
 //調用RFC函數
 IFunctionTemplate ft = mRepository.getFunctionTemplate("BAPI_MATERIAL_GET_DETAIL");
 JCO.Function f = ft.getFunction();
 
 //1.傳入參數為Field
    f.getImportParameterList().setValue("931029BA", "MATERIAL"); 
    f.getImportParameterList().setValue("1000", "PLANT");    
    mConnection.execute(f);
    //1.返回參數為Field
    JCO.Structure struct  = f.getExportParameterList().getStructure("MATERIAL_GENERAL_DATA");
    String name = struct.getString("MATL_DESC");
 System.out.println("物料名:"+name);
    String MATL_TYPE = struct.getString("MATL_TYPE");
    System.out.println("物料類型:"+MATL_TYPE);
    
   
    mRepository = new JCO.Repository("my_repository", mConnection);
    mConnection.disconnect();
  } catch (Exception ex) {
   ex.printStackTrace();
   System.exit(1);
   
  }
  
}
 
}
public class Main {
    
    public static void main(String[] args) {
        SAPLogon mySAP = new SAPLogon("800", "userid", "passwork", "zh", "21.4.13.2", "00");
        SAPServer myServer = new SAPServer(mySAP.mRepository);       
        myServer.start();
    }
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.