本文主要是介绍DELPHI 调用SAP—RFC 示例,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
DELPHI 调用SAP—RFC 示例
Logon to the R3-system with the componente TSAPLogOnControl
In this example the form TForm1 contains the following components:
Component Function
SAPLogOnControl1 SAP ActiveX-Component to logon to the system
Button1 Button to start the procedure
unit s_logon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, OleCtrls, SAPLogonCtrl_TLB, StdCtrls,Grids ;
type
TForm1 = class(TForm)
SAPLogonControl1: TSAPLogonControl;
Panel1: TPanel;
StaticText1: TStaticText;
Button1: TButton;
procedure SAPLogonControl1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Connection :variant;
implementation
{$R *.DFM}
procedure TForm1.SAPLogonControl1Click(Sender: TObject);
begin
(* define connection *)
Connection:= SAPLogOnControl1.NewConnection;
(* start LogOn *)
if Connection.LogOn(0,false) = true then
begin
showmessage('Logon O.K.');
Button1.Enabled:= true;
end
else
begin
ShowMessage('Error on Logon :-(((');
SAPLogonControl1.Enabled:=true;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
(* cut connection *)
Connection.LogOff;
ShowMessage('System LogOff...');
SAPLogonControl1.Enabled:=true;
Button1.enabled :=false;
end;
end.
top of page
Example 2:
Logon to the R3-system with the Component TSAPLogOnControl and SilentLogOn
In this example the form TForm1 contains the following components:
Component Function
SAPLogOnControl1 SAP ActiveX-Component to logon to the system
Button1 Button to cut the connection
unit s_logon;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, OleCtrls, SAPLogonCtrl_TLB, StdCtrls,Grids ;
type
TForm1 = class(TForm)
SAPLogonControl1: TSAPLogonControl;
Panel1: TPanel;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
StaticText1: TStaticText;
Button1: TButton;
procedure SAPLogonControl1Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
Connection :variant;
implementation
{$R *.DFM}
procedure TForm1.SAPLogonControl1Click(Sender: TObject);
begin
(* define connection and it's parameters *)
Connection := SAPLogoncontrol1.newConnection;
(* In some GUI-versions the username *)
(* must be written in uppercase !!! *)
Connection.User := AnsiUpperCase(Edit1.text);
Connection.System := 'IDS';
Connection.Client := '800';
Connection.ApplicationServer := 'SAPIDES';
Connection.SystemNumber := '00';
Connection.Password := Edit2.text;
Connection.Language := 'DE' ;
SAPLogonControl1.Enabled := false;
if Connection.LogOn(0,true) = true then
(* parameter "true" : SilentLogOn *)
begin
ShowMessage('Logon O.K.');
Button1.Enabled:= true;
end
else
begin
ShowMessage('Error on logon :-(((');
SAPLogonControl1.Enabled:=true;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
(* cut connection *)
Connection.LogOff;
ShowMessage('System LogOff...');
SAPLogonControl1.Enabled:=true;
Button1.Enabled :=false;
end;
end.
top of page
Example 3:
Read all costcenters with the function RFC_READ_TABLE
In this example the form TForm1 contains the following components:
Component function
SAPFunctions1 SAP ActiveX-component to connect RFC/BAPI
Grid
这篇关于DELPHI 调用SAP—RFC 示例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!