Академический Документы
Профессиональный Документы
Культура Документы
Call).
Preparao Delphi
Para este exemplo ser necessrio importar no Delphi os ActiveX Controls SAP Logon
Control e SAP Remote Function Call Control, conforme as imagens abaixo:
Informaes necessrias
Para chamar no SAP a RFC ser necessrio alguns parmetros, que podem ser obtidos
conforme as telas das imagens abaixo:
o
o
o
Servidor de aplicao
N da instncia
ID sist.
o
o
o
o
Mandante
Usurio
Senha
Idioma de logon
Exemplo
public
{ Public declarations }
end;
var
Form1: TForm1;
Connection, Funct, Table: Variant;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
(* define connection and it's parameters *)
Connection := SAPLogoncontrol1.newConnection;
Connection.ApplicationServer := '127.0.0.1'; //Servidor de aplicao
Connection.SystemNumber := '00'; //N da instncia
Connection.System := 'ECP'; //ID sist.
(* In some GUI-versions the username *)
(* must be written in uppercase !!! *)
Connection.Client := '000'; //Mandante
Connection.User := AnsiUpperCase(Edit1.text); //Usurio
Connection.Password := Edit2.text; //Senha
Connection.Language := 'PT' ; //Idioma de logon
Button1.Enabled := False;
if Connection.LogOn(0, True) = true then
(* parameter "true" : SilentLogOn *)
begin
ShowMessage('Logon O.K.');
Button2.Enabled := True;
Button3.Enabled := True;
end
else
begin
ShowMessage('Error on logon :-(((');
Button1.Enabled := True;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
(* cut connection *)
Connection.LogOff;
ShowMessage('System LogOff...');
Button1.Enabled := True;
Button2.Enabled := False;
Button3.Enabled := False;
end;
procedure TForm1.Button3Click(Sender: TObject);
var
txt: string;
r, c: integer;
begin
(* assign the existing connection to the *)
(* component SAPFunctions1
*)
SAPFunctions1.Connection := Connection;
Funct := SAPFunctions1.add('RFC_READ_TABLE');
Funct.exports('QUERY_TABLE').value := 'CSKT';
if not Funct.call then
showMessage(Funct.exception)
else begin
Table := Funct.tables.item('DATA');
grid.RowCount := Table.rowcount + 1;
grid.ColCount := 3;
grid.cells[0,0] := 'Client';
grid.cells[1,0] := 'CostCent-No';
grid.cells[2,0] := 'CostCent-Des.';
for r := 1 to grid.rowCount -1 do begin
txt := Table.value(r,1);
grid.cells[0,r] := copy(txt,0,3);
grid.cells[1,r] := copy(txt,9,10);
grid.cells[2,r] := copy(txt,27,20);
end;
AutoSizeGrid(grid);
grid2.rowCount := Table.rowcount + 1;
grid2.ColCount := Table.columncount;
for r := 1 to grid2.RowCount -1 do begin
for c := 1 to grid2.ColCount do begin
grid2.cells[c - 1,r] := Table.value(r, c);
end;
end;
AutoSizeGrid(grid2);
end;
end;
procedure TForm1.AutoSizeGrid(Grid: TStringGrid);
const
ColWidthMin = 10;
var
C, R, W, ColWidthMax: integer;
begin
for C := 0 to Grid.ColCount - 1 do begin
ColWidthMax := ColWidthMin;
for R := 0 to (Grid.RowCount - 1) do begin
W := Grid.Canvas.TextWidth(Grid.Cells[C, R]);
if W > ColWidthMax then
ColWidthMax := W;
end;
Grid.ColWidths[C] := ColWidthMax + 5;
end;
end;
end.
Consideraes