Top Banner
Connect for SAP ® Getting Started Guide
51
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide

Page 2: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 2 of 51 © 2000-2009 gs-soft AG, Switzerland

1 About this document ......................................................................................... 4

2 About Connect for SAP® ................................................................................... 5

3 Architectural overview ....................................................................................... 6

3.1 RFC function architecture .......................................................................................................................... 7

3.1.1 Data representation ............................................................................................................................... 7

3.1.2 Data mapping ......................................................................................................................................... 8

3.1.3 Early and late function binding .......................................................................................................... 10

3.2 Client applications ..................................................................................................................................... 12

3.2.1 Using connection aliases ................................................................................................................... 13

3.2.2 Features of transactional calls ........................................................................................................... 13

3.3 Server applications .................................................................................................................................... 14

3.3.1 Specifying registration parameters ................................................................................................... 15

3.3.2 Features of transactional calls ........................................................................................................... 15

4 Installation ....................................................................................................... 16

4.1 System requirements ................................................................................................................................ 16

4.2 Installing librfc32.dll ................................................................................................................................... 16

4.2.1 Short path .............................................................................................................................................. 16

4.2.2 Full path ................................................................................................................................................. 17

4.3 Additional requirements ........................................................................................................................... 18

4.4 Installing into CodeGear Delphi or C++ Builder .................................................................................... 19

4.4.1 Building Connect for SAP® binaries ................................................................................................. 19

4.4.2 Installing components ......................................................................................................................... 20

4.5 Installing into FPC / Lazarus ..................................................................................................................... 22

4.5.1 Limitation and known issues ............................................................................................................. 22

4.5.2 Installing components ......................................................................................................................... 22

5 HowTo call ABAP function with Connect for SAP® ........................................ 23

6 HowTo work with Connect for SAP® components ......................................... 25

7 How to write a Server function with Connect for SAP®.................................. 28

8 HowTo write a Server function with Connect for SAP® as NT service .......... 29

Appendix A – Data type and mapping .................................................................... 31

Appendix B – Early and late function binding......................................................... 33

Appendix C – Defining server parameters ............................................................. 34

Appendix D – Transaction management in Connect for SAP® server application 35

Page 3: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 3 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix E – Connect for SAP® component list ................................................... 38

Appendix F – Listing of Connect for SAP® client application ................................. 40

Appendix G – Listing of Connect for SAP® server as console application ............ 42

Appendix H – Listing of Connect for SAP® server as NT service .......................... 48

Page 4: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 4 of 51 © 2000-2009 gs-soft AG, Switzerland

1 About this document

This document might be very useful for CodeGear Delphi developers in:

• Building applications that are SAP system clients;

• Extending functionality of SAP application server by creating external non-SAP server programs.

You can find in this guide general overview of Connect for SAP® software and its possible applications.

This document helps to understand main architectural concepts of Connect for SAP® work: information

on RFC function architecture, different types of data mapping and function binding. You will also learn

general concepts of creating client and server applications based on Connect for SAP®. The guide

provides the developer with necessary installation instructions and gives a brief overview of components

installed.

Here are some practical suggestions “How to …”. They give process overviews of creating simple both

client and server applications and contains some recommendations how to use Connect for SAP®

components during design time as well as at run time.

If you need to get any additional information not mentioned in this guide do not hesitate to contact us:

https://www.gs-soft.com/confluence/display/SAPx Product web page

[email protected] Email address

Page 5: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 5 of 51 © 2000-2009 gs-soft AG, Switzerland

2 About Connect for SAP®

Connect for SAP® is an object-oriented software library. It has been specially designed for access to

SAP application servers using CodeGear Delphi™ and for building partner server programs run in non-

SAP systems. Connect for SAP® is a flexible and versatile tool for:

• Integration of existing Delphi™ applications with SAP systems. This feature allows corporations to

use their own information systems and create superstructures offering new opportunities;

• Development of new systems and applications that have access to SAP application server as

clients;

• Extension of SAP system functionality through Connect for SAP® by building external non-SAP

servers. This feature gives the developer an opportunity to avoid costs connected with ABAP

training as all functionality extensions are implemented in Delphi™ programs.

Connect for SAP® encapsulates Remote Function Call (RFC) interface and offers high-level software

components and classes.

RFC API is a set of C-language routines that perform certain end user’s communication tasks and allow

execution of remote calls between two SAP Systems or between a SAP System and a non-SAP system.

RFC API supports a number of external systems, such as OS/2, Windows, as well as all of R/3-based

UNIX platforms. This feature makes it possible to use RFC functionality for interaction of a SAP System

with a C-program based on the platforms mentioned above (there exists a RFC SDK that includes RFC

library specific for each platform supported).

Page 6: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 6 of 51 © 2000-2009 gs-soft AG, Switzerland

3 Architectural overview

On Figure 1 you can see the way Delphi applications can interact with SAP system through Connect for

SAP®. Connect for SAP

® can be used both in client and server applications.

In the first case, when the developer wants to call an ABAP function he has to use Connect for SAP®

object methods and properties. Connect for SAP® packs all the necessary data and transfers the call to

the RFC library. In such a way the client request is sent to the SAP system. On receiving the request the

SAP application server processes it and returns the result. Connect for SAP® gets resulting data from

the RFC library and the developer can have access to it.

Client

Delphi application

SAPx

RFC libraryCall an ABAP RFC function

SAP R/3 system

Application server

ABAP RFC

functions

SAP gateway

Server

Delphi application

SAPx

RFC libraryCall an external function

Figure 1: Interaction of a SAP system with Delphi application based on Connect for SAP

®

In the second case Connect for SAP® server application is constantly waiting for SAP system client

request. When the request occurs Connect for SAP® receives and processes it. Connect for SAP

® also

undertakes to send the result to the SAP system in correct format.

Page 7: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 7 of 51 © 2000-2009 gs-soft AG, Switzerland

3.1 RFC function architecture

If you want to understand the way RFC function can be called and how to work with function parameters

it is necessary to examine RFC function architecture.

RFC function

Export

parametersTables

Import

parameters

Input data

Output data .

SAPx

RFC data types

Delphi data types

Figure 2: RFC function architecture

As it is shown on Figure 2 RFC function receives data from Export parameters; Import parameters

contain resulting data; whereas Tables can contain both input and output data. All data imported from

and exported to RFC function has its own format and internal order. These data formats, RFC data

types, differ from Delphi ones. That is why one of Connect for SAP® most important tasks is to map RFC

data types to Delphi ones and backwards.

3.1.1 Data representation

SAP R/3 servers are able to run on different types of computers. And they may have different than on

WinTel representations of integer and float data. Data representation should be changed, when data are

received from / transmitted to SAP R/3 server and data representations of server and client are different.

Connect for SAP® performs that for you.

Page 8: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 8 of 51 © 2000-2009 gs-soft AG, Switzerland

How Connect for SAP® will do that is controlled by alias parameters

TSAPxRFCAliasGS.DataFormat.IntType and TSAPxRFCAliasGS.DataFormat.FloatType. By default

they have values itAutoDetect and ftAutoDetect.

The alias parameter TSAPxRFCAliasGS.DataFormat.BytesPerChar specifies the server side character

data representation – bytes per char. By default it has value bcAutoDetect.

Using default values, Connect for SAP® will automatically detect server side data representation. In

some special cases, you can decide to force Connect for SAP® to expect some specified data

representation. It is not recommended, although.

3.1.2 Data mapping

RFC data types can be divided into three groups with different mapping methods: simple data type,

structured data type and tables.

3.1.2.1 Simple data types

Figure 3 shows concepts of simple RFC data type mapping (you can find more details on data mapping

procedure in Appendix A). If a data type has ambiguous mapping, the developer can definitely indicate

the target Delphi data type. Otherwise, Connect for SAP® maps this data type to the most appropriate

Delphi data type.

dtCharGS

Simple

RFC data types

dtNumGS

dtTimeGS

.

.

.

String

Delphi

data types

Int64

TDateTime

.

.

.

dtDateGS

Figure 3: Simple RFC data type mapping

Page 9: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 9 of 51 © 2000-2009 gs-soft AG, Switzerland

3.1.2.2 Structured data types

Unlike simple data types structured one, i.e. dtStructureGS, does not have Delphi analogues. Figure 4

illustrates how the Connect for SAP® wraps the dtStructureGS type by means of the

TSAPxRFCParameterGS class, which contains a field list of the TSAPxRFCFieldsListGS class. So the

structure corresponds to the field list, where an individual field of the TSAPxRFCFieldGS class

represents each structure item.

Connect for SAP® does not support nested structured data types. It means that each structure item

should be of simple data type (you can find more details on data mapping procedure in Appendix A).

Field list

Item 1

Structured

RFC data type

Item 2

Item N

.

.

.

Field 1

Parameter

Field 2

Field N

.

.

.

Figure 4: Wrapping structured RFC data type by Connect for SAP

®

Connect for SAP® includes TSAPxRFCvParamsGS component derived from TDataSet that, on the one

hand, offers clear and easy interface for Delphi developers and, on the other hand, works with RFC

library using RFC data types and formats. TSAPxRFCvParamsGS represents each function simple

parameter by single field, and structured parameter by one top level field with subfields. You can choose

which parameter types (input, output or both) TSAPxRFCvParamsGS includes by specifying

ParamKinds.

3.1.2.3 RFC table parameters

We should also pay more attention to the way Connect for SAP® works with function tables featuring

their own format. SAP RFC table parameter is like a structured parameter – it has field list, but may

contain multiple rows of data.

Page 10: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 10 of 51 © 2000-2009 gs-soft AG, Switzerland

Connect for SAP® includes TSAPxRFCvTableGS component derived from TDataSet that, on the one

hand, offers clear and easy interface for Delphi developers and, on the other hand, works with RFC

library using RFC data types and formats. TSAPxRFCvTableGS corresponds to one table parameter

with TableName name.

3.1.2.4 Unicode character data

Unicode support in Connect for SAP® depends on Delphi version:

• Pre-2009 Delphi versions (5-2007) does not support Unicode version of LIBRFC32.DLL. That

means, that for ‘CHAR’ data type and for object names, library always uses ANSI encoded

character data. Even if a server is in the Unicode mode.

• Delphi 2009 and higher supports Unicode version of LIBRFC32U.DLL. That means, that for

‘CHAR’ data type and for object names, library always uses Unicode UCS-2 encoded character

data.

The ‘STRING’ and ‘XMLDATA’ data types are always UTF8 encoded. For these data types, library

internally performs UTF8 <-> UCS2 transformation and always returns UCS2 encoded character data.

Connect for SAP® supports UTF8 encoded character data properly with LIBRFC32.DLL version is 6 or

higher.

3.1.3 Early and late function binding

There are two types of binding ABAP RFC functions with Connect for SAP® function objects in Connect

for SAP®, early and late binding.

Early binding means that an ABAP function name has been known at design time already. So Connect

for SAP® function object is statically defined. It is recommended to use Connect for SAP

® Explorer tool

to generate a wrapping code for the ABAP functions. That will save you a lot of time and will help you to

avoid lots of mistakes. See Connect for SAP® Explorer User Guide for details and restrictions applied to

code generation.

On the contrary, late binding allows the developer to call an ABAP function at run time dynamically. In

this case Connect for SAP® automatically gets the necessary metadata.

If we compare early and late binding:

Page 11: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 11 of 51 © 2000-2009 gs-soft AG, Switzerland

• Early binding has a higher productivity as it excludes application roundtrip to the SAP system for

metadata retrieval;

• Early binding allows to use Code Insight feature and find some mistakes during compile process;

• Early binding is sensitive to client and server Unicode mode, due to differences in structure layouts

for different Unicode modes;

• Late binding has smaller performance but wider flexibility;

The developer can choose one binding mode or another depending on the specific task (you can find

more details on quantitative indicators for early and late binding in Appendix B).

Page 12: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 12 of 51 © 2000-2009 gs-soft AG, Switzerland

3.2 Client applications

Figure 5 illustrates the architecture of a client application build with the Connect for SAP® components

using CodeGear Delphi.

Delphi application

SAPx

TSAPxRFCvFunctionGS TSAPxRFCvServerTableGS

TSAPxRFCvClientConnectionGS

TSAPxRFCvParamsGS TSAPxRFCvTableGS

RFC

TDataSource TDataSource TDataSource

Delphi client application

1

1

1

1

n

n n

n

1

n

Figure 5: Interaction of Connect for SAP® client components in an application.

The TSAPxRFCvClientConnectionGS component is responsible for connection to a SAP server. Use

Params property to specify connection parameters on fly or AliasName property to use predefined

connection alias. Set Connected to True to establish connection. Such components as

TSAPxRFCvFunctionGS and TSAPxRFCvServerTableGS use TSAPxRFCvClientConnectionGS object

to communicate with RFC library.

The main Connect for SAP® client component is TSAPxRFCvFunctionGS. It is responsible for

describing and executing of SAP function modules using SAP RFC library. Set Connection property to a

connection component. Use ObjName property to specify function name to call. The OutParams

Page 13: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 13 of 51 © 2000-2009 gs-soft AG, Switzerland

property represents output parameter collection, the InParams – input ones, the Table – table ones.

These property are not accessible at design-time.

The developer can use TSAPxRFCvParamsGS and TSAPxRFCvTableGS components to operate with

a TSAPxRFCvFunctionGS function parameters and tables. Set Func property to a function component.

Use TSAPxRFCvParamsGS.ParamKinds to specify parameter types (input, output or both) to represent.

Use TSAPxRFCvTableGS.TableName to specify table parameter to represent.

The components TSAPxRFCvParamsGS, TSAPxRFCvTableGS, and TSAPxRFCvServerTableGS

inherited from TDataSet can be linked with any data aware controls.

To build a client application you can use components as well as objects encapsulated into these

components, eg RFCFunction property of TSAPxRFCvFunctionGS.

3.2.1 Using connection aliases

A client application establishes communication with a SAP system through a SAP RFC library. A

connection is defined by a set of parameters, which has to be specified before connecting.

For convenience developers may use Connect for SAP® aliases to define connection parameters. An

alias is a named stored set of the parameters. By default they are stored in <windows>\

SAPxRFCAliases.ini file.

The developer can use Connect for SAP® Explorer (see Connect for SAP

® Explorer User Guide) to

maintain Connect for SAP® aliases, test them and explore the function modules.

3.2.2 Features of transactional calls

Connect for SAP® supports transactional functions. The transactional function should be called only

between starting and ending points of a transaction. These are distinctive features of transactional calls:

• CallType property of TSAPxRFCvFunctionGS should be set to ftTransactionalGS.

• TSAPxRFCvFunctionGS should have no import parameters.

• Only one function can be called within a singular transaction.

Page 14: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 14 of 51 © 2000-2009 gs-soft AG, Switzerland

3.3 Server applications

Figure 6 illustrates the architecture of a server application build with the Connect for SAP® components

using CodeGear Delphi.

SAPx

TSAPxRFCvServerFunctionGS

TSAPxRFCvServerConnectionGS

Delphi server application

1

n

1

1

RFC library

SAPxRFCServerApplication

1

n

Figure 6: Interaction of Connect for SAP

® server visual components in an application.

The TSAPxRFCvServerConnectionGS component is responsible for registration of a server on a

gateway and communication of the TSAPxRFCvServerFunctionGS components with a SAP system

through the SAP RFC library. Use CommandLine property to specify registration parameters. Set

Connected to True to establish registration. All request to functions registered with this connection are

handled in single thread in serialized fashion.

The main Connect for SAP® server component is TSAPxRFCvServerFunctionGS. It is responsible for

installing description and execution of requests to a custom RFC function using SAP RFC library. Set

Connection property to a server connection component. Use ObjName property to specify function

registration name. Create OnExecute handler, which will handle custom function request. The

OutParameters property represents output parameter collection, the InParameters – input ones, the

Tables – table ones. These properties are not accessible at design-time.

Page 15: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 15 of 51 © 2000-2009 gs-soft AG, Switzerland

And the SAPxRFCServerApplication is a singleton, controlling Connect for SAP® server application life

cycle. All TSAPxRFCvServerConnectionGS and TSAPxRFCvServerFunctionGS objects must be

created and setup before calling SAPxRFCServerApplication.Start. The method creates thread for each

server connection. Then each thread registers its server connection at gateway, installs transaction

control and installs all associated with this connection custom functions. Now the Connect for SAP®

server application is able to handle requests from external SAP systems.

The SAPxRFCServerApplication.Shutdown method stops the Connect for SAP® server application.

Server applications as well as client ones can be built on both Connect for SAP® components and

objects encapsulated into these components.

3.3.1 Specifying registration parameters

Server connection parameters can be specified in the command line when the server application is

starting. In this case command line parameters are automatically assigned to CommandLine property of

TSAPxRFCvServerConnectionGS component. Appendix C shows command line switches and their

meaning. When server starts it becomes possible to specify either PROGRAM_ID, GWHOST,

GWSERV and RFC_TRACE parameters or just a DESTINATION parameter solely.

In the second case you have to define entry named DESTINATION in the saprfc.ini file specifying all

connection parameters (see example in Appendix C). This way to specify server connection parameters

is much more flexible than the first one.

While using command line it is very important to remember that you cannot specify more than one set of

server connection parameters. So, for server applications with multiple connections the developer

should definitely and explicitly specify CommandLine property of TSAPxRFCvServerConnectionGS

component.

3.3.2 Features of transactional calls

Connect for SAP® supports transactional server functions. You can use transactional RFC to bundle

several remote functions into one logical unit of work (LUW) (with an automatic rollback mechanism in

case of error). With transactional RFC, generated LUWs are processed independently of each other.

This means, the order in which they are processed is not always the order in which they are generated.

Check

http://help.sap.com/saphelp_nw04/helpdata/EN/22/042ad7488911d189490000e829fbbd/content.htm for

more details.

Page 16: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 16 of 51 © 2000-2009 gs-soft AG, Switzerland

4 Installation

4.1 System requirements

Before installing Connect for SAP® ensure that:

• SAP RFC non-Unicode library version at least 4.6 is installed on your PC - librfc32.dll. It is

required for pre-2009 Delphi version tools.

• SAP RFC Unicode library version at least 4.6 is installed on your PC - librfc32u.dll. It is required

for Delphi 2009 and higher tools.

Notice. SAP RFC library may be installed as part of SAPgui installation.

Notice. SAP RFC library from SAP GUI v 6.x has a bug – each unload of librfc32.dll will result

memory loss around 6 Mb.

Notice. UTF8 character data is supported properly by SAP RFC library from SAP GUI v 6.x or

higher.

• SAP R/3 system you want to work with is at least Release 2.1.

• CodeGear Delphi™ 5 / 6 / 7 / 2005 / 2006 / 2009 / 2010 or CodeGear C++Builder™ 5 / 6 / 2006 /

2007 / 2009 / 2010 is installed on your PC.

Notice. Only Delphi 2009 and higher offers full Unicode support.

4.2 Installing librfc32.dll

There are two approaches to installing librfc32.dll on a workstation:

• Short - copy required SAP RFC runtime DLL’s from one workstation, where they are already

installed, to another one.

• Full – use SAP RFC runtime DLLs installer and Microsoft VC++ Runtime installer to guarantee,

that all required SAP RFC runtime files are deployed and installed on a workstation correctly.

4.2.1 Short path

In general, you will need to copy the few SAP RFC runtime DLL’s to the windows\system32 folder. Also,

it may be required to install the Microsoft VC++ Runtime DLL’s. Here we expect, that they are rather

already installed a workstation.

Page 17: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 17 of 51 © 2000-2009 gs-soft AG, Switzerland

To install librfc32.dll copy only librfc32.dll file.

To install librfc32u.dll copy files:

• librfc32u.dll

• icudt30.dll

• icuin30.dll

• icuuc30.dll

• libsapu16vc71.dll

• libsapucum.dll

4.2.2 Full path

To install librfc32.dll and / or librfc32u.dll, you will need:

• Go to the SAP software download center (http://service.sap.com/swdc). For that you should

have an account at SAP.

• To install librfc32u.dll:

o Search there for “SAP RFC SDK”, select the latest SAP RFC SDK version, Unicode, 32-

bit option. For example, “SAP RFC SDK UNICODE, 7.10”, then “Windows server on

IA32 32bit”. And download it.

o From command prompt execute SAPCAR –xvf <downloaded SAR file path>

o Copy required files to c:\windows\system32:

� lib\icudt30.dll

� lib\icuin30.dll

� lib\icuuc30.dll

� lib\libsapu16vc71.dll

� lib\libsapucum.dll

� bin\librfc32u.dll

• To install librfc32.dll:

o Search there for “SAP RFC SDK”, select the latest SAP RFC SDK version, Unicode, 32-

bit option. For example, “SAP RFC SDK, 7.10”, then “Windows server on IA32 32bit”.

And download it.

Page 18: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 18 of 51 © 2000-2009 gs-soft AG, Switzerland

o From command prompt execute SAPCAR –xvf <downloaded SAR file path>

o Copy required files to c:\windows\system32

� bin\librfc32.dll

• Read SAP Note 684106 and optionally :

o download and setup R3DLLINS.exe for SAP release 6.40 and 7.00

o download and setup vcredist_<platform>.exe (32-bit) for SAP release 4.6D EX2, 6.40

EX2, 7.10 from http://www.microsoft.com/downloads/details.aspx?FamilyID=200B2FD9-

AE1A-4A14-984D-389C36F85647&displaylang=en

4.3 Additional requirements

SAP user account used by Connect for SAP® client application should have all required privileges to

execute following RFC function modules:

Table 1: SAP R/3 function modules, used by Connect for SAP® software

Function module Used for Used by

RFC_GET_FUNCTION_INTERFACE To dynamically obtain

function module

interface from non-

Unicode servers.

TSAPxRFCFunctionGS,

TSAPxRFCvFunctionGS

RFC_GET_FUNCTION_INTERFACE_US To dynamically obtain

function module

interface from Unicode

servers.

TSAPxRFCFunctionGS,

TSAPxRFCvFunctionGS

RFC_GET_STRUCTURE_DEFINITION To dynamically obtain

record data type layout

from non-Unicode

servers.

TSAPxRFCFunctionGS,

TSAPxRFCvFunctionGS,

TSAPxRFCTableGS,

TSAPxRFCvTableGS

RFC_GET_UNICODE_STRUCTURE To dynamically obtain

record data type layout

from Unicode servers.

TSAPxRFCFunctionGS,

TSAPxRFCvFunctionGS,

TSAPxRFCTableGS,

TSAPxRFCvTableGS

Page 19: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 19 of 51 © 2000-2009 gs-soft AG, Switzerland

RFC_SYSTEM_INFO To get server

representation of

integer and float data

types.

TSAPxRFCClientConnectionGS,

TSAPxRFCvClientConnectionGS

RFC_READ_TABLE To read SAP server

tables data.

TSAPxRFCEasyDataMoveGS,

TSAPxRFCvServerTableGS

RFC_FUNCTION_SEARCH To show list of

accessible RFC

function modules

Connect for SAP ® Explorer

RFC_GROUP_SEARCH To show list of

accessible RFC

function groups.

Connect for SAP ® Explorer

4.4 Installing into CodeGear Delphi or C++ Builder

4.4.1 Building Connect for SAP® binaries

Connect for SAP® software includes a set of BAT command files. They may be used to build Connect for

SAP® binary files don’t running IDE, but from command line:

Table 2: Connect for SAP® command files

File name Tool

compileD5.bat Delphi 5

compileD6.bat Delphi 6

compileD7.bat Delphi 7

compileD2005Win32.bat Delphi 2005, Win32 platform

compileD2005Net.bat Delphi 2005, .Net platform

compileD2006Win32.bat Delphi 2006 / C++ Builder 2006,

Win32 platform

compileD2006Net.bat Delphi 2006, .Net platform

Page 20: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 20 of 51 © 2000-2009 gs-soft AG, Switzerland

compileD2007Win32.bat Delphi 2007 / C++ Builder 2006,

Win32 platform

compileD2007Net.bat Delphi 2007, .Net platform

compileD2009.bat Delphi 2009 / C++ Builder 2009

compileD2010.bat Delphi 2010 / C++ Builder 2010

compileBCB5.bat* C++ Builder 5*

compileBCB6.bat C++ Builder 6

*Note: Generally, we do not support C++ Builder 5 anymore. If you want to work with Connect for

SAP®

and C++ Builder 5; please contact us first.

All BAT files will automatically detect is the tool installed or not and where it is installed. And if the tool is

not installed you will get an error message about that.

The compiled binary files will be put into <SAPx>\Lib\<Tool> folder. For example, Delphi 2010 files will

be put into <SAPx>\Lib\Delphi2010.

4.4.2 Installing components

Installation of new components has become very easy due to the Delphi package system. To install

Connect for SAP®:

1. Run Delphi IDE.

2. Choose File -> Open. Set Files of type to Delphi package (*.dpk) and open appropriate Package

Project file in the Connect for SAP® installation directory:

Table 3: Connect for SAP® package files

Package name Tool

gsSAPxRFCD5.dpk Delphi 5

gsSAPxRFCD6.dpk Delphi 6

gsSAPxRFCD7.dpk Delphi 7

gsSAPxRFCD2005.dpk Delphi 2005 Win32 platform

gsSAPxRFCD2006.dpk Delphi / C++ Builder 2006 Win32

platform

Page 21: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 21 of 51 © 2000-2009 gs-soft AG, Switzerland

gsSAPxRFCD2007.dpk Delphi / C++ Builder 2007 Win32

platform

gssoft.SAPxRFCD2005.dpk Delphi 2005.Net platform

gssoft.SAPxRFCD2006.dpk Delphi 2006 .Net platform

gssoft.SAPxRFCD2007.dpk Delphi 2007 .Net platform

gsSAPxRFCD2009.dpk Delphi / C++ Builder 2009

gsSAPxRFCD2010.dpk Delphi / C++ Builder 2010

gsSAPxRFCbcb5.bpk* C++ Builder 5*

gsSAPxRFCbcb6.bpk C++ Builder 6

*Note: Generally, we do not support C++ Builder 5 anymore. If you want to work with Connect for

SAP®

and C++ Builder 5; please contact us first.

3. Click on Compile button in Package window and then press Install button.

The new components should appear in the Delphi Component Palette (Figure 7).

Figure 7: Delphi component palette after successful installation of Connect for SAP®.

You can find list of all Connect for SAP® components in Appendix E.

Page 22: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 22 of 51 © 2000-2009 gs-soft AG, Switzerland

4.5 Installing into FPC / Lazarus

4.5.1 Limitation and known issues

The current Connect for SAP (r) sources was tested with FPC 2.2.1. The following limitations are known:

1. Only Win32 platform is supported. Later will be added Linux support.

2. Design-time property editors, component editors are not yet ported.

3. Connect for SAP (r) Explorer is not ported and will be not ported.

4. The FPC 2.2.1 does not support ftADT dataset data type. As consequence of that

TSAPxRFCvParamsGS represents structured parameters as flat list.

The following issues are known:

1. TTimeField.AsDateTime does not work due to a bug in FPC 2.2.1. Use AsString instead. See

comment in TSAPxRFCvCustomTableGS.SetFieldData for technical details.

2. TVarByteField.AsString does not return variable length value due to a bug in FPC 2.2.1. Expect

always fixed-length value of TField.Size bytes length. See comment in

TSAPxRFCvCustomTableGS.SetFieldData for technical details.

4.5.2 Installing components

To install Connect for SAP® into Lazarus IDE:

1. Run Lazarus IDE.

2. Choose Package -> Open Package File (*.lpk). Open gsSAPxRFCLaz.lpk file in the Connect for

SAP® installation directory.

3. Click on Compile button in Package window and then press Install button. You will be prompted to

Rebuild Lazarus, answer Yes. That will take some time.

Page 23: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 23 of 51 © 2000-2009 gs-soft AG, Switzerland

5 HowTo call ABAP function with Connect for SAP®

In order to examine how to call an ABAP function developer can create a simple application that calls

ABAP function RFC_GET_NAMETAB. This function returns as result time stamp of table creation

(CRSTAMP). Input parameter TABNAME specifies the table name.

The developer has to take the following steps:

1. Create a new application form with a set of standard components on it (see Figure 8).

2. Locate on the form such Connect for SAP® components as TSAPxRFCvClientConnectionGS and

TSAPxRFCvFunctionGS.

Figure 8: The main form of the application calling ABAP function module RFC_GET_NAMETAB

3. Set the key components properties according to Table 4.

Table 4: Key components properties and their values

Component name Class name Property

ClientConnection TSAPxRFCvClientConnectionGS AliasFileName = <Full name of alias file>

AliasName = <Any valid alias>

GetNameTab TSAPxRFCvFunctionGS Connection = ClientConnection

ObjName = ‘RFC_GET_NAMETAB’

btnConnect TButton OnClick = btnConnectClick

btnDisconnect TButton OnClick = btnDisconnectClick

btnExecute TButton OnClick = btnExecuteClick

Page 24: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 24 of 51 © 2000-2009 gs-soft AG, Switzerland

4. Implement the event handlers: btnConnectClick, btnDisconnectClick and btnExecuteClick as it is

shown on Listing 1.

Listing 1: Implementation of event handlers

procedure TfrmMain.btnExecuteClick(Sender: TObject);

begin

with GetNameTab do begin

Prepared := True;

InParams.ParameterByName('TABNAME').AsString := edtTableName.Text;

ExecFunction;

edtStamp.Text :=

OutParams.ParameterByName('HEADER').SubFields.FieldByName('CRSTAMP').AsString;

end;

end;

{ --------------------------------------------------------------------------- }

procedure TfrmMain.btnConnectClick(Sender: TObject);

begin

ClientConnection.Connected := True;

end;

{ --------------------------------------------------------------------------- }

procedure TfrmMain.btnDisconnectClick(Sender: TObject);

begin

ClientConnection.Connected := False;

end;

5. Run the application.

6. Press Connect button and log in the SAP system.

7. Specify the target table name and press Execute button. The final result is shown on Figure 9

Figure 9: The result of RFC_GET_NAMETAB function call

Page 25: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 25 of 51 © 2000-2009 gs-soft AG, Switzerland

6 HowTo work with Connect for SAP® components

Let us take as an example a simple application that calls ABAP function RFC_GET_FUNC_LOC_DATA.

This function returns information on locked SAP DB table by its name (you can find complete listing of

this application in Appendix F).

To build it using Connect for SAP® components the developer has to take the following steps:

1. Create a new application form with a set of standard components on it.

2. Locate on the created form the following Connect for SAP® components:

TSAPxRFCvClientConnectionGS, TSAPxRFCvFunctionGS, TSAPxRFCvTableGS and

TSAPxRFCvParamsGS (see Figure 10).

Figure 10: The main application form with Connect for SAP® client components located on it.

3. Now you have access to function parameters and tables using data aware controls such as

TDBGrid, TDBEdit, TDBLabel and others. To make it possible key components properties should be

maintained in accordance with Table 5.

Table 5: Maintaining key Connect for SAP® components properties for work using data aware

controls.

Component name Class name Property

ClientConnection TSAPxRFCvClientConnectionGS AliasFileName = <Full name of alias file>

AliasName = <Any valid alias>

Page 26: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 26 of 51 © 2000-2009 gs-soft AG, Switzerland

GetFuncData TSAPxRFCvFunctionGS Connection = ClientConnection

ObjName = ‘RFC_GET_FUNC_LOC_DATA’

PInput TSAPxRFCvParamsGS Func = ‘GetFuncData’

ParamKinds = [ipIn]

POutput TSAPxRFCvParamsGS Func = ‘GetFuncData’

ParamKinds = [ipOut]

Table TSAPxRFCvTableGS Func = ‘GetFuncData’

TableName = ‘SAP_FIELD_DATA’

dsrInput TDataSource DataSet = PInput

dsrOutput TDataSource DataSet = Poutput

dsrTable TDataSource DataSet = Table

edtFuncLoc TDBEdit DataSource = dsrInput

DataField = ‘I_FUNC_LOC’

grdOutput TDBGrid DataSource = dsrOutput

grdTable TDBGrid DataSource = dsrTables

btnConnect TButton OnClick = btnConnectClick

btnDisconnect TButton OnClick = btnDisconnectClick

btnPrepare TButton OnClick = btnPrepareClick

btnExecute TButton OnClick = btnExecuteClick

4. Run the application and connect to the SAP system by clicking on Connect button. When clicking on

Prepare button you prepare the GetFuncData function to access to its parameter list and tables

(Listing 2 shows implementation of btnConnectClick and btnPrepareClick event handlers). When the

function is prepared, its parameters and tables will be displayed in DB grids.

Listing 2: Implementation of btnConnectClick and btnPrepareClick event handlers

procedure TfrmMain.btnConnectClick(Sender: TObject);

begin

ClientConnection.Connected := True;

end;

procedure TfrmMain.btnPrepareClick(Sender: TObject);

begin

GetFuncData.Prepare;

PInput.Active := True;

POutput.Active := True;

Table.Active := True;

end;

Page 27: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 27 of 51 © 2000-2009 gs-soft AG, Switzerland

5. Enter I_FUNC_LOC input function parameter value use edtFuncLoc control. Then press the Execute

button. Figure 11 shows the results of executing RFC_GET_FUNC_LOC_DATA ABAP function

module.

Figure 11: Function results received with data aware controls.

Page 28: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 28 of 51 © 2000-2009 gs-soft AG, Switzerland

7 How to write a Server function with Connect for SAP®

To enhance SAP system functionality by implementing a non-SAP server we are going to build, as an

example, a server console application that supports transactional calls. The application has a single

server function that is very simple as it can only write its input parameters to its table.

To build such server application the developer should take the following steps (you can find complete

listing of this application in Appendix G):

1. Create a new console application TransServer and its main class TxServer

2. Add the following main Connect for SAP® server objects to TxServer as class members:

• FSConnection1 of TSAPxRFCServerConnectionGS type

• FSFunction1 of TSAPxRFCServerFunctionGS type

3. Implement InitConnection and InitFunction procedures to initialize server connection

(FSConnection1) and server function (FSFunction1). The developer can specify server connection

parameters either in program code, for example in InitConnection procedure, or use capability of

Connect for SAP® to take these parameters out of command line. In our example we are going to

use the second way, therefore the server program should be launched with the following command

line:

TransServer.exe –aMY_SERVER_ID –gmyserver.mydomain.com –xsapgw00

Before running Connect for SAP® server you have to create the SAP destination that is used in ABAP

program to call Connect for SAP® server function (SM59 transaction).

4. Implement server function actions into HandleExecute event handler. HandleError event handler

contains actions that have to be performed when an error occurs. If the server has to support

transactions, then it is necessary to implement transaction events handlers such as

HandleCheckTID, HandleCommit, HandleRollback and HandleConfirm.

Transactional functions cannot have output parameters.

5. Write code that will launch and terminate the application server using Start and Shutdown methods

of TSAPxRFCServerApplicationGS object. Use SAPxRFCServerApplication function to access to

TSAPxRFCServerApplicationGS global object.

Page 29: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 29 of 51 © 2000-2009 gs-soft AG, Switzerland

8 HowTo write a Server function with Connect for SAP® as NT service

The majority of server programs in Windows NT are implemented as services. Connect for SAP® server

can be implemented as NT service as well. Server of this kind is built on TService standard CodeGear

Delphi class and uses TService events to control Connect for SAP® application server. To design such

Connect for SAP® server the developer should take the following steps (you can find complete listing of

this application in Appendix H):

1. Create a new Service Application.

2. Add one or more TSAPxRFCvServerConnectionGS and TSAPxRFCvServerFunctionGS

components.

3. Maintain the main components properties as it is shown in Table 6.

Table 6: Maintaining of key Connect for SAP® components work properties using data aware

controls.

Component (object) name

Class name Property

FSConnection1 TSAPxRFCvServerConnectionGS CommandLine.IniDest = ‘DEST1’

OnCheckTID = ‘HandleCheckTID’

OnCommit = HandleCommit

OnConfirm = HandleConfirm

OnRollback = HandleRollback

FSConnection2 TSAPxRFCvServerConnectionGS CommandLine.IniDest = ‘DEST2’

OnCheckTID = ‘HandleCheckTID’

OnCommit = HandleCommit

OnConfirm = HandleConfirm

OnRollback = HandleRollback

FSFunction11 TSAPxRFCvServerFunctionGS Connection = FSConnection1

ObjName = ‘SAPXRFCF11’

OnExecute = FSTxFunctionExecute

FSFunction12 TSAPxRFCvServerFunctionGS Connection = FSConnection1

ObjName = ‘SAPXRFCF12’

OnExecute = FSFunctionExecute

Page 30: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 30 of 51 © 2000-2009 gs-soft AG, Switzerland

FSFunction21 TSAPxRFCvServerFunctionGS Connection = FSConnection2

ObjName = ‘SAPXRFCF21’

OnExecute = FSTxFunctionExecute

FSFunction22 TSAPxRFCvServerFunctionGS Connection = FSConnection2

ObjName = ‘SAPXRFCF22’

OnExecute = FSFunctionExecute

4. Define destinations ‘DEST1’ and ‘DEST2’ in saprfc.ini file.

5. Implement handlers for the following TService’s events: OnStart, OnStop, OnPause and

OnContinue. These handlers are quite simple (see Listing 3).

Listing 3: Implementation of event handlers controlling Connect for SAP ® application server.

procedure TSAPxRFCServer.ServiceStart(Sender: TService; var Started: Boolean);

begin

SAPxRFCServerApplication.Start;

Started := not SAPxRFCServerApplication.Terminated;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServiceStop(Sender: TService; var Stopped: Boolean);

begin

SAPxRFCServerApplication.Shutdown;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServicePause(Sender: TService; var Paused: Boolean);

begin

SAPxRFCServerApplication.Pause;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServiceContinue(Sender: TService; var Continued: Boolean);

begin

SAPxRFCServerApplication.Resume;

end;

6. Include all server function actions into HandleExecute event handler.

7. If the server has to support transactions, it is necessary to implement event handlers such as

HandleCheckTID, HandleCommit, HandleRollback and HandleConfirm.

Page 31: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 31 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix A – Data type and mapping

Mapping of simple RFC data type to Delphi data and field types

RFC data type Delphi data type

(see gsSAPxRFCStdObj)

Delphi field type

(see gsSAPxRFCvClient)

dtCharGS Pre Delphi 2009 or Lazarus:

• AnsiString

Delphi 2009 and higher:

• UnicodeString

Pre Delphi 2009 or Lazarus:

• ftString (size <= 8192)

• ftMemo (size > 8192)

Delphi 2009 and higher:

• ftWideString (size <= 8192)

• ftWideMemo (size > 8192)

dtNumGS Int64 • ftSmallInt (size <= 4)

• ftInteger (size <= 9)

• ftLargeInt (size > 9)

dtByteGS RawByteString • ftVarBytes (size <= 8192)

• ftBlob (size > 8192)

dtBCDGS • Integer

• Int64

• Currency

• Double

• String

ftFloat

dtIntGS Integer ftInteger

dtInt1GS ShortInt ftSmallInt

dtInt2GS SmallInt ftSmallInt

dtFloatGS Double ftFloat

dtDateGS TDateTime ftDate

dtTimeGS TDateTime ftTime

dtStringGS UnicodeString • ftWideString (size <= 8192)

• ftWideMemo (size > 8192)

dtXMLDataGS UnicodeString ftWideMemo

dtXStringGS RawByteString ftBlob

dtLineTypeGS Not supported Not supported

Page 32: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 32 of 51 © 2000-2009 gs-soft AG, Switzerland

Conversion of dtStructureGS data type to Delphi field type

RFC data type Delphi data type

(see gsSAPxRFCStdObj)

Delphi field type

(see gsSAPxRFCvClient)

dtStructureGS

Delphi:

• ftADT

Lazarus:

• a flat list of simple fields

Converting RFC table parameters to Delphi data type

RFC data type Delphi data type

(see gsSAPxRFCStdObj)

Delphi field type

(see gsSAPxRFCvClient)

RFC table parameter TSAPxRFCTableGS TSAPxRFCvTableGS

TSAPxRFCParameterGS

TSAPxRFCFieldsListGS

TSAPxRFCFieldGS

1 … 1

1 … N

Page 33: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 33 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix B – Early and late function binding

Listing 4: Early binding. Wrapping code generated for RFC_READ_TABLE ABAP function by Connect for SAP ® Explorer.

TSAPxRFCRFC_READ_TABLEFuncGS = class(TSAPxRFCFunctionGS)

private

procedure SetDELIMITER(const AValue: String);

function GetDELIMITER: String;

function GetDATA: TSAPxRFCTAB512TableGS;

public

constructor Create; override;

property DELIMITER: String read GetDELIMITER write SetDELIMITER;

property DATA: TSAPxRFCTAB512TableGS read GetDATA;

end;

implementation

procedure Execute;

begin

// working with TSAPxRFCRFC_READ_TABLEFuncGS object interface

with FCFunction as TSAPxRFCRFC_READ_TABLEFuncGS do begin

DELIMITER := ‘%’;

ExecFunction;

with DATA do begin

{ do something with table ‘DATA’ }

end;

end;

end;

Listing 5: Late binding. Using a dynamically prepared function.

procedure Execute;

begin

// working with TSAPxRFCFunctionGS object interface

with FCFunction do begin

ObjName := ‘RFC_READ_TABLE’;

Prepared := True;

InParams.ParameterByName('DELIMITER').AsString := ‘%’;

ExecFunction;

with Tables.TableByName('DATA') do begin

{ do something with table ‘DATA’ }

end;

end;

end;

Statistics of function execution for different binding modes

Binding mode Early binding Late binding

Single function call ~ 0.161 sec ~ 0.46 sec

Sequential function calls (100 times) ~14.191 sec ~14.882 sec

Page 34: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 34 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix C – Defining server parameters

Command line switches and their meanings

Listing 6: Example of destination list in saprfc.ini file

// -----------------------------------------------------------------------

// SAPx server destinations

// -----------------------------------------------------------------------

DEST=S1

TYPE=R

PROGID=SAPXRFCTEST_PROGID1

GWHOST=myserver.mydomain.com

GWSERV=sapgw00

Command line switch Meaning

-a<PROGRAM_ID> Identifier of server connection registered on SAP gateway

-g<GWHOST> Host name of SAP gateway

-x<GWSERV> Service name on SAP gateway

-t<RFC_TRACE> Indicator of tracing

-D<DESTINATION> Destination name in saprfc.ini file

Page 35: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 35 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix D – Transaction management in Connect for SAP® server application

Connect for SAP® supports transactional server functions. SAP R/3, the RFC library and Connect for

SAP® server connection communicate in two phases (see Figure 12: Scheme of calling a transactional

function):

• The first phase (F1) – Function transfer

• The second phase (F2) – Confirmation

Function transfer phase is initiated in ABAP program and is divided into three parts:

• T1 – OnCheckTID event handler has to check TID status, update it and return corresponding

check result

• T2 – OnExecute event handler should contain the required RFC server function implementation

• T3 (T3’) – OnCommit (OnRollback) event handler updates TID status and commits (rolls back)

database (non-SAP database) transaction(s)

Confirmation phase starts as soon as RFC library informs SAP system about successful T3 (not T3’).

TSAPxRFCvServerConnectionGS component receives confirmation of the current transaction

immediately. In OnConfirm event handler the developer should update TID status (delete). After this

phase is over current transaction is successfully completed on both sides.

A simple example of transaction management is shown in Listing 7: Transactional management.

Page 36: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 36 of 51 © 2000-2009 gs-soft AG, Switzerland

SAP R/3 system Delphi server application

SAP tRFC

component

SAPx

TSAPxRFCvServerConnectionGS

OnCheckTID

OnCommit

OnRollback

OnConfirm

RFC library

F1

F2

T1

T3

T3'

T4

// Check and update TID

// Update TID and commit DB

if necessary

// Update TID and rollback DB

if necessary

// Update (delete) TID

OnExecuteT2

// Execute some actions

Figure 12: Scheme of calling a transactional function

Listing 7: Transactional management

procedure TxServer.HandleCheckTID(Sender: TObject; const ATID: String;

var AResult: TSAPxRFCCheckTIDResultGS);

begin

if CheckStatus(ATID) then // whether the transaction has not started

UpdateStatus(ATID, tsCreated) // updating the transaction’s status

else

AResult := crCancelGS; // rejecting the transaction

end;

{-----------------------------------------------------------------------------}

procedure TxServer.HandleCommit(Sender: TObject; const ATID: String);

begin

UpdateStatus(ATID, tsExecuted);

CommitDB(ATID); // committing non-SAP database transaction

end;

{-----------------------------------------------------------------------------}

procedure TxServer.HandleConfirm(Sender: TObject; const ATID: String);

begin

UpdateStatus(ATID, tsDeleted);

end;

{-----------------------------------------------------------------------------}

Page 37: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 37 of 51 © 2000-2009 gs-soft AG, Switzerland

procedure TxServer.HandleRollback(Sender: TObject; const ATID: String);

begin

RollbackDB(ATID); // rolling non-SAP database transaction back

end;

Page 38: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 38 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix E – Connect for SAP® component list

Connect for SAP® building components are divided into two groups: components for client programs and

for non-SAP server programs. In the following sections you can find description of each of these groups.

Client components

Connect for SAP® components used in client programs with access to SAP application server RFC

functions are called client components.

Using Connect for SAP® Explorer

Connect for SAP® Explorer is a specially designed tool that offers the developer SAP system dictionary

information on RFC objects. For more detailed information about this tool, please, refer to Connect for

SAP® Explorer User Guide.

TSAPxRFCvClientConnectionGS

The TSAPxRFCvClientConnectionGS is the main client component. It connects to the specified

SAP system and supports data exchange between a client program and the SAP system.

TSAPxRFCvFunctionGS

The TSAPxRFCvFunctionGS component allows execution of an ABAP RFC function module. It

contains sets of input and output parameters and table lists that are used for access to the function

module data.

TSAPxRFCvTableGS

The TSAPxRFCvTableGS is a TDataSet component descendant; that is why it can be used by

data aware controls. It allows access to the specified table from the TSAPxRFCvFunctionGS table list.

TSAPxRFCvServerTableGS

The TSAPxRFCvServerTableGS is also a TDataSet component descendant; that is why it can be

used by data aware controls as well. It allows to get dictionary information on specified SAP DB table

(fields description) and data stored within this table.

TSAPxRFCvParamsGS

Page 39: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 39 of 51 © 2000-2009 gs-soft AG, Switzerland

The TSAPxRFCvParamsGS corresponds to a set of function parameters. It allows to edit and

display a set of parameters using data aware controls.

Server components

The set of Connect for SAP® server components allows implementation of non-SAP server programs

that enhance SAP system functionality.

TSAPxRFCvServerConnectionGS

The TSAPxRFCvServerConnectionGS is the main component for non-SAP server programs. It

registers all supported server functions on SAP gateway; processes client requests and dispatches

them.

TSAPxRFCvServerFunctionGS

The TSAPxRFCvServerFunctionGS component allows implementation of a certain part of server

functionality. Every TSAPxRFCvServerFunctionGS component belongs to the specified server

connection and can receive client requests only from it.

Page 40: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 40 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix F – Listing of Connect for SAP® client application

Listing 8: Connect for SAP® client application

unit ClientApp;

interface

uses

Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

Dialogs, gsSAPxRFCvClient, DB, StdCtrls, Grids, DBGrids, Mask, DBCtrls;

type

{ --------------------------------------------------------------------------- }

TfrmMain = class(TForm)

ClientConnection: TSAPxRFCvClientConnectionGS;

GetFuncData: TSAPxRFCvFunctionGS;

btnExecute: TButton;

btnConnect: TButton;

grpInput: TGroupBox;

grpOutput: TGroupBox;

grpTables: TGroupBox;

btnDisconnect: TButton;

Table: TSAPxRFCvTableGS;

dsrInput: TDataSource;

dsrOutput: TDataSource;

dsrTables: TDataSource;

POutput: TSAPxRFCvParamsGS;

edtFuncLoc: TDBEdit;

PInput: TSAPxRFCvParamsGS;

grdOutput: TDBGrid;

GrdTable: TDBGrid; btnPrepare: TButton;

lblFieldName: TLabel;

procedure btnExecuteClick(Sender: TObject);

procedure btnConnectClick(Sender: TObject);

procedure btnDisconnectClick(Sender: TObject);

procedure btnPrepareClick(Sender: TObject);

procedure FormClose(Sender: TObject; var Action: TCloseAction);

end;

var

frmMain: TfrmMain;

implementation

{$R *.dfm}

{ --------------------------------------------------------------------------- }

procedure TfrmMain.btnExecuteClick(Sender: TObject);

begin

GetFuncData.ExecFunction;

end;

{ --------------------------------------------------------------------------- }

procedure TfrmMain.btnConnectClick(Sender: TObject);

begin

ClientConnection.Connected := True;

end;

Page 41: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 41 of 51 © 2000-2009 gs-soft AG, Switzerland

{ --------------------------------------------------------------------------- }

procedure TfrmMain.btnDisconnectClick(Sender: TObject);

begin

ClientConnection.Connected := False;

end;

{ --------------------------------------------------------------------------- }

procedure TfrmMain.btnPrepareClick(Sender: TObject);

begin

GetFuncData.Prepare;

PInput.Active := True;

POutput.Active := True;

Table.Active := True;

end;

{ --------------------------------------------------------------------------- }

procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction);

begin

ClientConnection.Connected := False;

end;

end.

Page 42: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 42 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix G – Listing of Connect for SAP® server as console application

Listing 9: Connect for SAP® server as console application

program TransServer;

{$APPTYPE CONSOLE}

uses

Windows, SysUtils, gsSAPxRFCvServer, StdCtrls, gsSAPxRFCServer, gsSAPxRFCBase,

gsSAPxRFCvClient, gsSAPxRFCStdObj, Classes, dbtables, db;

type

TSAPxRFCABAPTEXTTableGS = class;

TSAPxRFCZMY_STRUCTUREStrGS = class;

TSAPxRFCZMY_SERVER_FUNCTIONFuncGS = class;

{-----------------------------------------------------------------------------}

{ TxServer }

{-----------------------------------------------------------------------------}

TxServer = class(TObject)

private

FSConnection1: TSAPxRFCServerConnectionGS;

FSFunction1: TSAPxRFCZMY_SERVER_FUNCTIONFuncGS;

procedure InitConnection;

procedure InitFunction;

procedure HandleExecute(AFunction: TSAPxRFCServerFunctionGS);

procedure HandleError(Sender: TObject; E: Exception;

var AErrAction: TSAPxRFCErrorActionGS);

procedure HandleCheckTID(Sender: TObject; const ATID: String;

var AResult: TSAPxRFCCheckTIDResultGS);

procedure HandleCommit(Sender: TObject; const ATID: String);

procedure HandleConfirm(Sender: TObject; const ATID: String);

procedure HandleRollback(Sender: TObject; const ATID: String);

public

constructor Create;

destructor Destroy; override;

procedure Start;

procedure Shutdown;

end;

{-----------------------------------------------------------------------------}

{ TSAPxRFCABAPTEXTTableGS }

{-----------------------------------------------------------------------------}

TSAPxRFCABAPTEXTTableGS = class(TSAPxRFCTableGS)

private

procedure SetLINE(const AValue: String);

function GetLINE: String;

public

constructor Create; override;

property LINE: String read GetLINE write SetLINE;

end;

{-----------------------------------------------------------------------------}

{ TSAPxRFCZMY_STRUCTUREStrGS }

{-----------------------------------------------------------------------------}

TSAPxRFCZMY_STRUCTUREStrGS = class(TSAPxRFCParameterGS)

private

procedure SetTABNAME(const AValue: String);

Page 43: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 43 of 51 © 2000-2009 gs-soft AG, Switzerland

function GetTABNAME: String;

procedure SetFLAG(const AValue: String);

function GetFLAG: String;

procedure InstallStructure;

public

constructor Create; override;

property TABNAME: String read GetTABNAME write SetTABNAME;

property FLAG: String read GetFLAG write SetFLAG;

end;

{-----------------------------------------------------------------------------}

{ TSAPxRFCZMY_SERVER_FUNCTIONFuncGS }

{-----------------------------------------------------------------------------}

TSAPxRFCZMY_SERVER_FUNCTIONFuncGS = class(TSAPxRFCServerFunctionGS)

private

function GetASTAT: TSAPxRFCZMY_STRUCTUREStrGS;

function GetDATA: TSAPxRFCABAPTEXTTableGS;

function GetFTABNAME: string;

procedure SetFTABNAME(Value: string);

public

constructor Create; override;

property ASTAT: TSAPxRFCZMY_STRUCTUREStrGS read GetASTAT;

property FTABNAME: string read GetFTABNAME write SetFTABNAME;

property DATA: TSAPxRFCABAPTEXTTableGS read GetDATA;

end;

{-----------------------------------------------------------------------------}

{ TxServer }

{-----------------------------------------------------------------------------}

constructor TxServer.Create;

begin

FSConnection1 := TSAPxRFCServerConnectionGS.Create;

FSFunction1 := TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.Create;

InitConnection;

InitFunction;

end;

{-----------------------------------------------------------------------------}

destructor TxServer.Destroy;

begin

FSConnection1.Free;

FSFunction1.Free;

inherited Destroy;

end;

{-----------------------------------------------------------------------------}

procedure TxServer.InitConnection;

begin

with FSConnection1 do begin

OnError := HandleError;

OnCheckTID := HandleCheckTID;

OnCommit := HandleCommit;

OnConfirm := HandleConfirm;

OnRollback := HandleRollback;

end;

end;

{-----------------------------------------------------------------------------}

procedure TxServer.InitFunction;

Page 44: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 44 of 51 © 2000-2009 gs-soft AG, Switzerland

begin

// the initialization of server function

with FSFunction1 do begin

Connection := FSConnection1;

OnExecute := HandleExecute;

end;

end;

{-----------------------------------------------------------------------------}

procedure TxServer.Start;

begin

SAPxRFCServerApplication.Start;

end;

{-----------------------------------------------------------------------------}

procedure TxServer.Shutdown;

begin

SAPxRFCServerApplication.Shutdown;

end;

{-----------------------------------------------------------------------------}

procedure TxServer.HandleExecute(AFunction: TSAPxRFCServerFunctionGS);

var

sStructDump, sTabName: String;

begin

if AFunction is TSAPxRFCZMY_SERVER_FUNCTIONFuncGS then

with AFunction as TSAPxRFCZMY_SERVER_FUNCTIONFuncGS do begin

sTabName := FTABNAME;

sStructDump := ASTAT.TABNAME + '; ' + ASTAT.FLAG;

DATA.Append;

DATA.LINE := sTabName + '; ' + sStructDump;

DATA.Post;

end;

end;

{-----------------------------------------------------------------------------}

procedure TxServer.HandleError(Sender: TObject; E: Exception;

var AErrAction: TSAPxRFCErrorActionGS);

begin

{ Error handling }

end;

{-----------------------------------------------------------------------------}

procedure TxServer.HandleCheckTID(Sender: TObject; const ATID: String;

var AResult: TSAPxRFCCheckTIDResultGS);

begin

{ Check status of transaction with ATID }

{ if the transaction has not been started, then }

{ AResult := crOkGS, else AResult := crCancelGS }

end;

{-----------------------------------------------------------------------------}

procedure TxServer.HandleCommit(Sender: TObject; const ATID: String);

begin

{ do DB Commit }

{ Update status of transaction with ATID }

end;

{-----------------------------------------------------------------------------}

Page 45: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 45 of 51 © 2000-2009 gs-soft AG, Switzerland

procedure TxServer.HandleConfirm(Sender: TObject; const ATID: String);

begin

{ Update status of transaction with ATID }

end;

{-----------------------------------------------------------------------------}

procedure TxServer.HandleRollback(Sender: TObject; const ATID: String);

begin

{ do DB Rollback }

end;

{-----------------------------------------------------------------------------}

{ TSAPxRFCABAPTEXTTableGS }

{-----------------------------------------------------------------------------}

constructor TSAPxRFCABAPTEXTTableGS.Create;

begin

inherited Create;

TableType := dtCharGS;

with Fields.AddField do begin

Name := 'LINE';

DataType := dtCharGS;

DataSize := 72;

Offset := 0;

end;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCABAPTEXTTableGS.SetLINE(const AValue: String);

begin

Fields[0].AsString := AValue;

end;

{-----------------------------------------------------------------------------}

function TSAPxRFCABAPTEXTTableGS.GetLINE: String;

begin

Result := Fields[0].AsString;

end;

{-----------------------------------------------------------------------------}

{ TSAPxRFCZMY_STRUCTUREStrGS }

{-----------------------------------------------------------------------------}

constructor TSAPxRFCZMY_STRUCTUREStrGS.Create;

begin

inherited Create;

InstallStructure;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCZMY_STRUCTUREStrGS.SetTABNAME(const AValue: String);

begin

SubFields[0].AsString := AValue;

end;

{-----------------------------------------------------------------------------}

function TSAPxRFCZMY_STRUCTUREStrGS.GetTABNAME: String;

begin

Result := SubFields[0].AsString;

end;

Page 46: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 46 of 51 © 2000-2009 gs-soft AG, Switzerland

{-----------------------------------------------------------------------------}

procedure TSAPxRFCZMY_STRUCTUREStrGS.SetFLAG(const AValue: String);

begin

SubFields[1].AsString := AValue;

end;

{-----------------------------------------------------------------------------}

function TSAPxRFCZMY_STRUCTUREStrGS.GetFLAG: String;

begin

Result := SubFields[1].AsString;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCZMY_STRUCTUREStrGS.InstallStructure;

var

oStr: TSAPxRFCStructureCacheItemGS;

i: Integer;

begin

oStr := FSAPxRFCEnvironment.StructureCache.FindStructure('ZMY_STRUCTURE');

if oStr = nil then begin

oStr := FSAPxRFCEnvironment.StructureCache.Add;

with oStr do begin

StructName := 'ZMY_STRUCTURE';

with Elements.AddElement do begin

Name := 'TABNAME';

DataType := dtCharGS;

DataSize := 30;

Offset := 0;

end;

with Elements.AddElement do begin

Name := 'FLAG';

DataType := dtCharGS;

DataSize := 1;

Offset := 30;

end;

end;

oStr.Install;

end;

DataType := dtStructureGS;

TypeHandle := oStr.TypeHandle;

SubFields.Clear;

for i := 0 to oStr.Elements.Count - 1 do

oStr.Elements[i].CreateField(SubFields);

end;

{-----------------------------------------------------------------------------}

{ TSAPxRFCZMY_SERVER_FUNCTIONFuncGS }

{-----------------------------------------------------------------------------}

constructor TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.Create;

begin

inherited Create;

Name := 'ZMY_SERVER_FUNCTION';

with InParameters.AddParameterEx(TSAPxRFCZMY_STRUCTUREStrGS) do begin

Name := 'FSTAT';

DataSize := 31;

end;

with InParameters.AddParameter do begin

Name := 'FTABNAME';

DataSize := 30;

Page 47: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 47 of 51 © 2000-2009 gs-soft AG, Switzerland

DataType := dtCharGS;

end;

with Tables.AddTableEx(TSAPxRFCABAPTEXTTableGS) do begin

Name := 'FDATA';

RecordSize := 72;

Open;

end;

end;

{-----------------------------------------------------------------------------}

function TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.GetASTAT: TSAPxRFCZMY_STRUCTUREStrGS;

begin

Result := InParameters[0] as TSAPxRFCZMY_STRUCTUREStrGS;

end;

{-----------------------------------------------------------------------------}

function TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.GetDATA: TSAPxRFCABAPTEXTTableGS;

begin

Result := Tables[0] as TSAPxRFCABAPTEXTTableGS;

end;

{-----------------------------------------------------------------------------}

function TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.GetFTABNAME: string;

begin

Result := InParameters[1].AsString;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCZMY_SERVER_FUNCTIONFuncGS.SetFTABNAME(Value: string);

begin

InParameters[1].AsString := Value;

end;

{-----------------------------------------------------------------------------}

var

Srv: TxServer;

F1: TextFile;

Ch: Char;

begin

Srv := TxServer.Create;

try

Srv.Start;

AssignFile(F1, '');

Reset(F1);

try

repeat

Read(F1, Ch);

until UpperCase(Ch) = 'Q';

finally

CloseFile(F1);

end;

finally

Srv.Shutdown;

Srv.Free;

end;

end.

Page 48: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 48 of 51 © 2000-2009 gs-soft AG, Switzerland

Appendix H – Listing of Connect for SAP® server as NT service

Listing 10: Connect for SAP® server as NT service

unit fMain;

interface

uses

Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,

gsSAPxRFCvServer, gsSAPxRFCServer, gsSAPxRFCBase, gsSAPxRFCStdObj, Db, DBTables;

type

{-----------------------------------------------------------------------------}

{ TSAPxRFCService }

{-----------------------------------------------------------------------------}

TTransStatus = (tsCreated, tsExecuted);

TSAPxRFCServer = class(TService)

FSConnection1: TSAPxRFCvServerConnectionGS;

FSFunction21: TSAPxRFCvServerFunctionGS;

FSFunction11: TSAPxRFCvServerFunctionGS;

FSConnection2: TSAPxRFCvServerConnectionGS;

FSFunction12: TSAPxRFCvServerFunctionGS;

FSFunction22: TSAPxRFCvServerFunctionGS;

procedure ServiceStart(Sender: TService; var Started: Boolean);

procedure ServicePause(Sender: TService; var Paused: Boolean);

procedure ServiceContinue(Sender: TService; var Continued: Boolean);

procedure ServiceCreate(Sender: TObject);

procedure FSFunctionExecute(AFunction: TSAPxRFCServerFunctionGS);

procedure FSTxFunctionExecute(AFunction: TSAPxRFCServerFunctionGS);

procedure ServiceExecute(Sender: TService);

procedure ServiceStop(Sender: TService; var Stopped: Boolean);

procedure HandleCommit(Sender: TObject; const ATID: String);

procedure HandleConfirm(Sender: TObject; const ATID: String);

procedure HandleRollback(Sender: TObject; const ATID: String);

procedure HandleCheckTID(Sender: TObject; const ATID: String;

var AResult: TSAPxRFCCheckTIDResultGS);

procedure ServiceDestroy(Sender: TObject);

private

FTransList: TStringList;

procedure CreatingOnFly;

public

function GetServiceController: TServiceController; override;

end;

var

SAPxRFCServer: TSAPxRFCServer;

implementation

{$R *.DFM}

{-----------------------------------------------------------------------------}

procedure ServiceController(CtrlCode: DWord); stdcall;

begin

SAPxRFCServer.Controller(CtrlCode);

end;

{-----------------------------------------------------------------------------}

Page 49: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 49 of 51 © 2000-2009 gs-soft AG, Switzerland

{ TSAPInfoService }

{-----------------------------------------------------------------------------}

function TSAPxRFCServer.GetServiceController: TServiceController;

begin

Result := ServiceController;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServiceStart(Sender: TService; var Started: Boolean);

begin

SAPxRFCServerApplication.Start;

Started := not SAPxRFCServerApplication.Terminated;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServicePause(Sender: TService; var Paused: Boolean);

begin

SAPxRFCServerApplication.Pause;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServiceStop(Sender: TService; var Stopped: Boolean);

begin

SAPxRFCServerApplication.Shutdown;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServiceContinue(Sender: TService; var Continued: Boolean);

begin

SAPxRFCServerApplication.Resume;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServiceCreate(Sender: TObject);

begin

FTransList := TStringList.Create;

CreatingOnFly;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServiceDestroy(Sender: TObject);

begin

FTransList.Free;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.FSFunctionExecute(AFunction: TSAPxRFCServerFunctionGS);

begin

{ non-transactional actions }

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.FSTxFunctionExecute(AFunction: TSAPxRFCServerFunctionGS);

begin

{ transactional actions }

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.ServiceExecute(Sender: TService);

Page 50: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 50 of 51 © 2000-2009 gs-soft AG, Switzerland

begin

while not Terminated do

ServiceThread.ProcessRequests(True);

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.CreatingOnFly;

var

i: Integer;

oFSFunction: TSAPxRFCvServerFunctionGS;

begin

for i := 0 to ComponentCount - 1 do

if Components[i] is TSAPxRFCvServerFunctionGS then begin

oFSFunction := TSAPxRFCvServerFunctionGS(Components[i]);

oFSFunction.InParameters.Clear;

oFSFunction.OutParameters.Clear;

with oFSFunction.InParameters.AddParameter do begin

{ specifying a set of input parameters }

end;

with oFSFunction.OutParameters.AddParameter do begin

{ specifying a set of output parameters }

end;

end;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.HandleCheckTID(Sender: TObject; const ATID: String;

var AResult: TSAPxRFCCheckTIDResultGS);

begin

if FTransList.IndexOf(ATID) = -1 then begin

FTransList.AddObject(ATID, TObject(tsCreated));

AResult := crOkGS;

end

else

AResult := crCancelGS;

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.HandleCommit(Sender: TObject; const ATID: String);

var

i: Integer;

begin

i := FTransList.IndexOf(ATID);

if i <> -1 then

FTransList.Objects[i] := TObject(tsExecuted);

{ DB commit }

end;

{-----------------------------------------------------------------------------}

procedure TSAPxRFCServer.HandleConfirm(Sender: TObject; const ATID: String);

var

i: Integer;

begin

i := FTransList.IndexOf(ATID);

if i <> -1 then

FTransList.Delete(i);

end;

{-----------------------------------------------------------------------------}

Page 51: Connect for SAP Getting Started

Connect for SAP®

Getting Started Guide - Page 51 of 51 © 2000-2009 gs-soft AG, Switzerland

procedure TSAPxRFCServer.HandleRollback(Sender: TObject; const ATID: String);

begin

{ DB rollback }

end;

end.