Bapi/RFC with Delphi (Series 4) -- use tsapfunctions (Delphi source code with logon dialog box)

Source: Internet
Author: User
Tags define function rfc rowcount

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.