|
<< Click to Display Table of Contents >> Navigation: All About SAP Interface > SAP r/3 and Delphi > Create SAP - Delphi Connection using SAP ActiveX |
Objective |
|
Support |
|
Contributor |
Albertus Reinandang ( reinandang@yahoo.com ) |
Requirement
All step is already tested using this requirement
1.SAP GUI 6.40 Patch Level 0-21 or SAP GUI 7.10 Patch Level 0 (download)
2.Borland Delphi 6 (Update 1 and 1) or Borland Delphi 7 or Code Gear Delphi 2005-2007 (download)
3.Windows 2000 or XP
In SAP system, there are roles that we must pass through SAP Logon to access SAP feature. SAP Logon need a special codes to be a standard SAP Logon system, which is:
•Client (R/3 System, client number from logon)
> A client in the r/3 system that you want to connect to
•ApplicationServer (Name of Application Server )
> The name of the host that you want to connect to
•SystemNumber ( System Number server SAP )
> Specify the system number (e.g. 00) of the SAP System that you want to connect to
•System ( System ID)
> Specify the system ID (e.g. OSS) of the SAP System that you want to connect to
•User ( User Logon Name )
•Password ( User Password )
•Language ( System Language )
If you not completely all the condition of that code above, you can’t using/accessing a feature in SAP GUI ActiveX, especially “SAP Functions” .
Installed Component
1.Standard Delphi Component
2.SAP ActiveX ( TSAPLogonControl and TSAPFunction )
____________________________________________________________________________
SAPLogonControl Concept and Format:
… Declare a New Connection …
… Fill Connection Variable …
… login …
Example:
…
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, StdCtrls, Oleauto;
…
SAPLogonControl1 := CreateOleObject('SAP.LogonControl.1');
Connection:= SAPLogoncontrol1.newConnection;
if Connection.LogOn(0,false) = true then
showMessage('Connect to SAP.');
…
>> … LogOn(0,false) … if you set to False then Dialog Login Menu will be appear.
>> … Oleauto; … You must add this to CreateOleObject
Note : “Connect to SAP” = it’s mean ‘You have Succeed Login to SAP !!’
The following Example show how to used SAP Login Control:
No |
Description |
|
1 |
Difficulty |
Easy ( For beginner ) |
2 |
Delphi Component |
TButton |
Procedure:
1.Run Delphi Application
2.Create new Project/Application
3.Add one “ Button ” Component to a Form from ActiveX pallet.

No |
Component |
Properties |
Value |
1 |
TButton |
Name |
BLogon |
|
|
Caption |
&R/3 Logon |
|
|
Others |
Default |
4.Add OnClick event on SAPLogonControl1 component with code bellow :
procedure TForm1.BLogonClick (Sender: TObject);
Var SAPLogonControl1, Connection : VARIANT ;
begin
SAPLogonControl1 := CreateOleObject('SAP.LogonControl.1');
Connection:= SAPLogoncontrol1.newConnection;
if Connection.LogOn(0,false) = true then
showMessage('Connect to SAP.');
end;
5.Press “ Run “ button for testing your code.
____________________________________________________________________________
Create SAP Logon with input dialog
No |
Description |
|
1 |
Difficulty |
Easy ( For beginner ) |
2 |
Delphi Component |
TButton |
|
|
TEdit |
TLabel |
Procedure:
1.Run Delphi Application
2.Create new Project/Application
3.Add one “ SAPLogonControl ” Component to a Form from ActiveX pallet.
4.Add and place it the others component like a picture bellow :

No |
Commponent |
Properties |
Value |
1 |
TButton |
Name |
BLogon |
|
|
Caption |
&R/3 Logon |
|
|
Others |
Default |
2 |
TEdit |
Name |
eApplicationServer |
|
|
Text |
Null (Empty) |
3 |
TEdit |
Name |
eSystemNumber |
|
|
Text |
Null (Empty) |
4 |
TEdit |
Name |
eClient |
|
|
Text |
Null (Empty) |
5 |
TEdit |
Name |
eSystem |
|
|
Text |
Null (Empty) |
6 |
TEdit |
Name |
eUsername |
|
|
Text |
Null (Empty) |
7 |
TEdit |
Name |
ePassword |
|
|
Text |
Null (Empty) |
8 |
TEdit |
Name |
eLanguage |
|
|
Text |
Null (Empty) |
5.Add OnClick event on SAPLogonControl1 component with code bellow :
procedure TForm1.BLogonClick (Sender: TObject);
Var SAPLogonControl1, Connection : VARIANT ;
begin
SAPLogonControl1 := CreateOleObject('SAP.LogonControl.1');
Connection:= SAPLogoncontrol1.newConnection;
Connection.Client := eClient.Text;
Connection.ApplicationServer := eAppilcationServer.Text;
Connection.SystemNumber := eSystemNumber.Text;
Connection.System := eSystem.Text;
Connection.User := Ansiuppercase(eUsername.text);
Connection.Password := ePassword.text;
Connection.Language := eLanguage.Text;
if Connection.LogOn(0,true) = true then
showMessage('Connect to SAP.');
end;
6.Press “ Run “ button for testing your code.
____________________________________________________________________________
Calling and Using RFC/BAPIs from SAP R/3
BAPIs (Business Application Program Interfaces) is SAP business objects held in the Business Object Repository (BOR) encapsulate their data and processes. External access to the data and processes is only possible using specific methods.
RFC (Remote Function Call) is interfaces provided for communication between SAP Systems and with external partners.
The BAPIs and RFC in the R/3 System are currently implemented as function modules which are created and managed in the Function Builder (SE37). Not all SAP user can used a Function Builder. Only user who have an access key from SAP can used all the feature in Function Builder. You can get Access key from http://service.sap.com.
In RFC or BAPI design there are 5 variable type, which is Import, Export, Changing, Tables and Exceptions. The variable which used generally is Import, Export and Tables.

Import Variable in SAPFunctions is declare as a function “ exports “, while the Export variable is declare as a function “ imports “.
SAPFunctions Concept and Format:
… SAPFunction Connection …
… Calling SAPFunctions …
… Fill (upload) Import/Tables variable in SAP …
… Call (download) Export/Tables variable in SAP …
… Close Connection …
Example:
…
SAPFunctions1.Connection:= Connection;
Funct := SAPFunctions1.add('/CRYSTAL/GET_USER_LIST');
//Filled (upload) Import/Tables variable in SAP
Funct.exports('PERNR').value := Edit1.Text;
if not Funct.call then
//IF RFC or BAPI failed to call
showMessage(Funct.exception)
else
begin
//Called (download) Export and Tables variable in SAP
Table := Funct.Tables.item('USERACTGRP');
Edit2.Text:= Funct.exports('PERNR').value;
end;
…
The following Example show how to call RFC :
No |
Description |
|
1 |
Difficulty |
Middle |
2 |
Delphi Component |
TButton |
|
|
TEdit |
|
|
TLabel |
|
|
TPanel |
|
|
TStringGrid |
3 |
RFC names |
/CRYSTAL/GET_USER_LIST |
Procedure :
1.Run Delphi Application
2.Create new Project/Application
3.Add one “ SAPLogonControl ” and “SAPFunction” Component to a Form from ActiveX pallet.
4.Add and place it the others component like a picture bellow :

No |
Commponent |
Properties |
Value |
1 |
TButton |
Name |
BLogon |
|
|
Caption |
&R/3 Logon |
|
|
Others |
Default |
2 |
TEdit |
Name |
eApplicationServer |
|
|
Text |
Null (Empty) |
3 |
TEdit |
Name |
eSystemNumber |
|
|
Text |
Null (Empty) |
4 |
TEdit |
Name |
eClient |
|
|
Text |
Null (Empty) |
5 |
TEdit |
Name |
eSystem |
|
|
Text |
Null (Empty) |
6 |
TEdit |
Name |
eUsername |
|
|
Text |
Null (Empty) |
7 |
TEdit |
Name |
ePssword |
|
|
Text |
Null (Empty) |
8 |
TEdit |
Name |
eLanguage |
|
|
Text |
Null (Empty) |
10 |
TPanel |
Name |
Panel1 |
|
|
Caption |
Null (Empty) |
|
|
Align |
alLeft |
|
|
Width |
140 |
10 |
TStringGrid |
Name |
StringGrid1 |
|
|
DefaultColWidth |
100 |
|
|
DefaultRowHeight |
19 |
|
|
Align |
alClient |
5.Add OnShow event on Form
procedure TForm1.FormShow(Sender: TObject);
begin
//Configure StringGrid View
StringGrid1.ColCount:=8;
StringGrid1.Cells[0,0]:='No';
StringGrid1.Cells[1,0]:='MANDT';
StringGrid1.Cells[2,0]:='BNAME';
StringGrid1.Cells[3,0]:='SUBSYSTEM';
StringGrid1.Cells[4,0]:='AGR_NAME';
StringGrid1.Cells[5,0]:='FROM_DAT';
StringGrid1.Cells[6,0]:='TO_DAT';
StringGrid1.Cells[7,0]:='ORG_FLAG';
end;
6.Add OnClick event on BLogon button with this code bellow :
procedure TForm1.BLogonClick (Sender: TObject);
Var SAPLogonControl1, SAPFunctions1, Connection, Funct, Table : variant;
i :integer;
begin
SAPLogonControl1 := CreateOleObject('SAP.LogonControl.1');
SAPFunctions1 := CreateOleObject('SAP.Functions');
Connection:= SAPLogoncontrol1.newConnection;
Connection.Client := eClient.Text;
Connection.ApplicationServer := eAppilcationServer.Text;
Connection.SystemNumber := eSystemNumber.Text;
Connection.System := eSystem.Text;
Connection.User := Ansiuppercase(eUsername.text);
Connection.Password := ePassword.text;
Connection.Language := eLanguage.Text;
if Connection.LogOn(0,true) = true then
begin
//Declare RFC Conncetion
SAPFunctions1.Connection := Connection;
//Call RFC or BAPI
Funct := SAPFunctions1.add('/CRYSTAL/GET_USER_LIST');
//If RFC or BAPI doesn’t need any export variable (in SAP is Imports)
//Funct.exports(< variable name for Import in SAP >).value := < value >;
//Example:
//Funct.exports('PERNR').value := Edit1.Text;
if not Funct.call then
// IF RFC or BAPI failed to call
showMessage(Funct.exception)
else
begin
//Called (Download) table variable from RFC or BAPI
Table := Funct.Tables.item('USERACTGRP');
// If RFC or BAPI doesn’t need any import variable (in SAP is Export)
//< value >:= Funct.imports(<variable name for Export in SAP >).value ;
//Example:
//Edit2.Text:= Funct.imports('PERNR').value;
StringGrid1.rowCount := Table.rowcount + 1;
for i := 1 to StringGrid1.rowCount -1 do
begin
StringGrid1.cells[0,i] := IntToStr(i);
//Get value from table
//Table.Value(< data to >, < Field Name > )
StringGrid1.cells[1,i] := Table.Value(i,'MANDT');
StringGrid1.cells[2,i] := Table.Value(i,'BNAME');
StringGrid1.cells[3,i] := Table.Value(i,'SUBSYSTEM');
StringGrid1.cells[4,i] := Table.Value(i,'AGR_NAME');
StringGrid1.cells[5,i] := Table.Value(i,'FROM_DAT');
StringGrid1.cells[6,i] := Table.Value(i,'TO_DAT');
StringGrid1.cells[7,i] := Table.Value(i,'ORG_FLAG');
end;
StringGrid1.visible := True;
end;
//Close SAP Conncetion
Connection.LogOff;
end;
end;
7.Press “ Run “ button for testing your code.