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.");
}
}
}