Можно подключится к сап через компоненты делфи: TSAPFunctions и TSapLOGONcontrol. Примерно так:
Code:
unit SAP1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, SAPFunctionsOCX_TLB, OleCtrls, SAPLogonCtrl_TLB, StdCtrls, Grids;
type
TForm1 = class(TForm)
Button1: TButton;
SAPLogonControl1: TSAPLogonControl;
SAPFunctions1: TSAPFunctions;
Button2: TButton;
Edit1: TEdit;
Label1: TLabel;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
Table,Funct, Connection, Table1: VARIANT;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
Connection:= FOrm1.SAPLogonControl1.NewConnection;
Connection.LogOn(0,false);
IF Connection.LogOn(0,true) = true THen
Begin
ShowMessage('Logon O.K.');
Button2.Enabled:= true;
End
Else
Begin
ShowMessage('Error on logon :-(((');
SAPLogonControl1.Enabled:=true;
End;
End;
procedure TForm1.Button2Click(Sender: TObject);
var txt,vrem : string ;
r,r2,pole,pos : integer ;
begin
IF Connection.LogOn(0,true) = true Then
Begin
Form1.SAPFunctions1.Connection:= Connection;
Funct := SAPFunctions1.add('TABLE_ENTRIES_GET_VIA_RFC');
Funct.exports('TABNAME').value := trim(AnsiUpperCase(form1.Edit1.Text));
If not Funct.call then
showMessage(Funct.exception)
else begin
Table := Funct.tables.item('NAMETAB');
form1.StringGrid1.ColCount:=Table.rowCount+1;
For r:=1 TO StringGrid1.ColCount-1 Do
Begin
txt := Table.value(r,2);
StringGrid1.Cells[r-1,0]:= txt;
End;
Table1 := Funct.tables.item('TABENTRY');
form1.StringGrid1.rowCount:=Table1.rowCount+1;
Pos:=1;
For r:=1 TO StringGrid1.RowCount-1 Do
For r2:=1 TO StringGrid1.ColCount-1 DO
Begin
txt := Table1.value(r,1);
pole:= strToInt(Table.value(r2,10));
pos := strToInt(Table.value(r2,5));
StringGrid1.Cells[r2-1,r]:= copy(txt,pos,pole);
End;
End;
End
Else
showMessage('Соединение не установлено');
end;