1. Create a new form and add the following controls on the form
Component |
Function |
Sapfunctions1 |
SAP ActiveX-component to connect RFC/bapi |
Saplogoncontrol1 |
SAP ActiveX-component to logon to the system |
Grid |
Stringgrid to show the data's in the form |
Button1 |
Button to start the procedure |
2. The source code is as follows (use the rfc_read_table function to read the cost center)
Unit logon1;
Interface
Uses
Windows, messages, sysutils, classes, graphics, controls, forms, dialogs,
Extctrls, olectrls, stdctrls, sapfunctionsocx_tlb,
Grids, saplogonctrl_tlb;
Type
Tform1 = Class (tform)
Sapfunctions1: tsapfunctions;
Button2: tbutton;
Grid: tstringgrid;
Edit1: tedit;
Edit2: tedit;
Label1: tlabel;
Label2: tlabel;
Saplogoncontrol1: tsaplogoncontrol;
Procedure button2click (Sender: tobject );
Private
{Private-deklarationen}
Public
{Public-deklarationen}
End;
VaR
Form1: tform1;
Table, funct, connection: variant;
Implementation
{$ R *. DFM}
Procedure tform1.button2click (Sender: tobject );
VaR TXT: string;
R: integer;
Begin
Connection: = saplogoncontrol1.newconnection;
Connection. User: = ansiuppercase (edit1.text );
Connection. System: = 'kids ';
Connection. Client: = '000000 ';
Connection. applicationserver: = 'sapides ';
Connection. systemnumber: = '00 ';
Connection. Password: = edit2.text;
Connection. Language: = 'de ';
If connection. Logon (0, true) = true then
(* Parameter "true" = silentlogon *)
Begin
(* Assign the existing connection to *)
(* 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. 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;
Grid. Visible: = true;
End;
End;
End;
End.