1. Create a new form and add the following controls on the form
Component |
Function |
Sapfunctions1 |
SAP ActiveX-component to connect RFC/bapi |
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;
Type
Tform1 = Class (tform)
Sapfunctions1: tsapfunctions;
Button1: tbutton;
Grid: tstringgrid;
Procedure button1click (Sender: tobject );
Private
{}
Public
{}
End;
VaR
Form1: tform1;
Table, funct: variant;
Implementation
{$ R *. DFM}
Procedure tform1.button1click (Sender: tobject );
VaR TXT: string;
R: integer;
Begin
(* Define function *)
Funct: = sapfunctions1.add ('rfc _ read_table ');
(* Tell the function what table shocould be read *)
Funct. Exports ('query _ table'). Value: = 'cskt ';
(* Call the function *)
If not funct. Call then
(* On error show message *)
Showmessage (funct. Exception)
Else begin
(* Select table with the data's *)
Table: = funct. Tables. Item ('data ');
(* Addjust the stringgrid *)
Grid. rowcount: = table. rowcount + 1;
Grid. cells [0, 0]: = 'client ';
Grid. cells [1, 0]: = 'cost number ';
Grid. cells [2, 0]: = 'costcenter description ';
For R: = 1 to grid. rowcount-1 do begin
(* Select first dataset *)
TXT: = table. Value (R, 1 );
(* Because the RCF-function returns only one *)
(* String whitch contains all data's, *)
(* String must be cut to different parts *)
Grid. cells [0, R]: = copy (txt, 0, 3); (* client *)
Grid. cells [1, R]: = copy (txt, 9, 10); (* costcent-Number *)
Grid. cells [2, R]: = copy (txt, 27,20); (* costcent-Description *)
End;
Grid. Visible: = true;
End;
End;
End.