DELPHI/JAVA连接SAP

unit Unit1;
interface
uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, OleCtrls, SAPFunctionsOCX_TLB,
  SAPLogonCtrl_TLB;
type
  TForm1 = class(TForm)
    Button1: TButton;
    Panel1: TPanel;
    Panel2: TPanel;
    SAPLogonControl1: TSAPLogonControl;
    SAPFunctions1: TSAPFunctions;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
var
  Form1: TForm1;
  Tab,Funct, Connection : VARIANT ;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
   Connection                  := SAPLogoncontrol1.newConnection;
   Connection.User             := 'if1';
   Connection.System           := '00';
   Connection.Client           := '300';
   Connection.ApplicationServer:= '172.16.98.20';
   Connection.SystemNumber     := '00';
   Connection.Password         := '801104';
   Connection.Language         := 'ZH' ;
  if Connection.LogOn(0,true) = true then
  begin
    SAPFunctions1.Connection := Connection;
    funct := sapFunctions1.add('BAPI_MATERIAL_GET_DETAIL');
    funct.exports('MATERIAL').value := '000000000013022256';
    if not funct.call then
    showMessage(funct.exception)
    else
    begin
     tab := funct.imports.item('MATERIAL_GENERAL_DATA');
     Panel1.caption := tab.value(1);
     Panel2.caption := tab.value(6);
    end;
  end;
end;
end.
 
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
 
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
import com.sap.mw.jco.*;
public class SAP extends Object
{
 public static void main (String str[])
 {
  SAP app=new SAP();
 }
 int count;
 JCO.Client mConnection;
 JCO.Repository mRepository;
 String[] SAPInterfaces;
 
 public SAP()
 {
  try {
   // Logon info
    mConnection = JCO.createClient("300", // SAP client
                                       "if1", // userid
                                       "801104", // password
                                          null, // language
                                 "172.16.98.20", // application server host name
                                            "00"); // system number
   mConnection.connect();
   mRepository = new JCO.Repository("ARAsoft", mConnection);
   System.out.println("SAP连接成功");
  } catch (Exception ex) {
   ex.printStackTrace();
   System.exit(1);
  }
  JCO.Function function = null;
  JCO.Table codes = null;
  JCO.Table DATA=null;
  
  try
  {
   function=this.createFunction("ZRFC_READ_TABLE");
   if (function == null)
   {
    System.out.println(
     "BAPI_MATERIAL_GETLIST" + " not found in SAP.");
    System.exit(1);
   }
   codes = function.getTableParameterList().getTable("FIELDS");
   DATA =function.getTableParameterList().getTable("DATA");
   JCO.ParameterList input=function.getImportParameterList();
   input.setValue("MSEG", "QUERY_TABLE");
   input.setValue(20,"ROWCOUNT");
   mConnection.execute(function);
   System.out.println(Integer.toString(codes.getNumRows()));
    for (int i = 0; i < DATA.getNumRows();i++)
    {
     DATA.setRow(i);
     System.out.println(DATA.getString("WA"));
    }
  }
  catch (Exception ex)
  {
   ex.printStackTrace();
   System.exit(1);
  }
 }
 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.");
  }
 }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值